jquery 圖片縮放拖動(dòng)的簡(jiǎn)單實(shí)例
一、不使用jquery,簡(jiǎn)單的縮放:
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>onMouseWheel</TITLE>
<SCRIPT>
var count = 10;
function Picture()
{
count = Counting(count);
Resize(count);
return false;
}
function Counting(count){
if (event.wheelDelta >= 120)
count++;
else if (event.wheelDelta <= -120)
count--;
return count;
}
function Resize(count){
oImage.style.zoom = count + '0%';
oCounter.innerText = count + '0%';
}
</SCRIPT>
</HEAD>
<BODY>
<div align=center>
<span style="font-weight:bold">Size =
<span id="oCounter" style="color:red;">100%</span></span>
<img id="oImage" src="images/aaa.gif" onmousewheel="return Picture();" >
</div>
</BODY>
</HTML>
一、使用jquery,實(shí)現(xiàn)縮放和拖動(dòng):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<style type="text/css">
#imgBox
{
width: 200px;
height: 200px;
background: red;
overflow: hidden;
margin: auto;
position: relative;
}
#imgMain
{
position: relative;
top: -200px;
}
</style>
<script src="js/jquery-1.2.6.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
$(function () {
var event;
if ($.browser.mozilla) {
event = "DOMMouseScroll";
}
else {
event = "mousewheel";
}
$("#divBlock").bind(event,
function (e) {
var evt = window.event || e;
var newWidth;
var newHeight;
var newLeft;
var newTop;
var overHeight = $("#divBlock").height();
if (evt.detail > 0 || evt.wheelDelta < 0) {
newWidth = $("#imgMain").width() - 20;
newHeight = $("#imgMain").height() - 20;
newLeft = $("#imgMain").position().left + 10;
newTop = $("#imgMain").position().top + 10 - overHeight;
}
else {
newWidth = $("#imgMain").width() + 20;
newHeight = $("#imgMain").height() + 20;
newLeft = $("#imgMain").position().left - 10;
newTop = $("#imgMain").position().top - 10 - overHeight;
}
$("#imgMain").css({ left: newLeft + "px", top: newTop + "px" });
$("#imgMain").width(newWidth);
$("#imgMain").height(newHeight);
}
);
$("#divBlock").bind("mousedown", function (e) {
var xo = e.pageX;
var yo = e.pageY;
var imgLeft = $("#imgMain").position().left;
var imgTop = $("#imgMain").position().top;
var overHeight = $("#divBlock").height();
$("#divBlock").bind("mousemove", function (e) {
window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
var x = e.pageX;
var y = e.pageY;
var bX = $("#imgBox").offset().left;
var bY = $("#imgBox").offset().top;
$("#imgMain").css("left", x - bX - (xo - bX) + imgLeft);
$("#imgMain").css("top", y - bY - (yo - bY) - overHeight + imgTop);
});
});
$("#divBlock").bind("mouseup mouseout", function () {
$("#divBlock").unbind("mousemove");
});
});
</script>
</head>
<body>
<div id="imgBox">
<div style="width: 200px; height: 200px; cursor: pointer; position: relative; left: 0;
top: 0; filter: alpha(opacity=0); opacity: 0; -moz-opacity: 0; background: blue;
z-index: 999;" id="divBlock">
</div>
<img src="test.jpg" width="200" height="200" alt="" id="imgMain" />
</div>
</body>
</html>
- jQuery實(shí)現(xiàn)等比例縮放大圖片讓大圖片自適應(yīng)頁(yè)面布局
- jquery 圖片預(yù)加載 自動(dòng)等比例縮放插件
- 基于JQuery實(shí)現(xiàn)的圖片自動(dòng)進(jìn)行縮放和裁剪處理
- jquery實(shí)現(xiàn)圖片按比例縮放示例
- 基于jquery實(shí)現(xiàn)圖片相關(guān)操作(重繪、獲取尺寸、調(diào)整大小、縮放)
- jQuery實(shí)現(xiàn)的鼠標(biāo)滾輪控制圖片縮放功能實(shí)例
- jQuery圖片縮放插件smartZoom使用實(shí)例詳解
- JQuery 圖片延遲加載并等比縮放插件
- jQuery圖片預(yù)加載 等比縮放實(shí)現(xiàn)代碼
- 基于jquery的防止大圖片撐破頁(yè)面的實(shí)現(xiàn)代碼(立即縮放)
- jQuery實(shí)現(xiàn)的移動(dòng)端圖片縮放功能組件示例
相關(guān)文章
jquery關(guān)于圖形報(bào)表的運(yùn)用實(shí)現(xiàn)代碼
jquery 關(guān)于圖形報(bào)表的運(yùn)用實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-01-01jQuery實(shí)現(xiàn)移動(dòng)端下拉展現(xiàn)新的內(nèi)容回彈動(dòng)畫
這篇文章主要介紹了jQuery實(shí)現(xiàn)移動(dòng)端下拉展現(xiàn)新的內(nèi)容回彈動(dòng)畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-06-06IE中的File域無法清空使用jQuery重設(shè)File域
IE中的File域無法清空,可能你看到的是已經(jīng)沒有值了,其實(shí)它還是存在的,下面有個(gè)不錯(cuò)示例,大家可以參考下2014-04-04picLazyLoad 實(shí)現(xiàn)圖片延時(shí)加載(包含背景圖片)
下面小編就為大家?guī)硪黄猵icLazyLoad 實(shí)現(xiàn)圖片延時(shí)加載(包含背景圖片)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-07-07詳解JavaScript for循環(huán)中發(fā)送AJAX請(qǐng)求問題
這篇文章主要為大家剖析了JavaScript for循環(huán)中發(fā)送AJAX請(qǐng)求問題,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-03-03EasyUI學(xué)習(xí)之Combobox下拉列表(1)
這篇文章主要為大家詳細(xì)介紹了EasyUI學(xué)習(xí)之Combobox下拉列表的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12jQuery實(shí)現(xiàn)的簡(jiǎn)單手風(fēng)琴效果示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)的簡(jiǎn)單手風(fēng)琴效果,結(jié)合實(shí)例形式分析了jQuery基于事件響應(yīng)、頁(yè)面元素屬性動(dòng)態(tài)操作實(shí)現(xiàn)手風(fēng)琴效果的方法,需要的朋友可以參考下2018-08-08jQuery實(shí)現(xiàn)的網(wǎng)頁(yè)左側(cè)在線客服效果代碼
這篇文章主要介紹了jQuery實(shí)現(xiàn)的網(wǎng)頁(yè)左側(cè)在線客服效果代碼,涉及簡(jiǎn)單的jQuery頁(yè)面動(dòng)畫顯示與隱藏效果實(shí)現(xiàn)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-10-10jQuery中scrollLeft()方法用法實(shí)例
這篇文章主要介紹了jQuery中scrollLeft()方法用法,實(shí)例分析了scrollLeft()方法的功能、定義及獲取或設(shè)置匹配元素相對(duì)滾動(dòng)條左側(cè)的偏移(offset)量時(shí)的使用技巧,需要的朋友可以參考下2015-01-01