jquery 圖片縮放拖動的簡單實例
一、不使用jquery,簡單的縮放:
<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,實現(xiàn)縮放和拖動:
<!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實現(xiàn)等比例縮放大圖片讓大圖片自適應頁面布局
- jquery 圖片預加載 自動等比例縮放插件
- 基于JQuery實現(xiàn)的圖片自動進行縮放和裁剪處理
- jquery實現(xiàn)圖片按比例縮放示例
- 基于jquery實現(xiàn)圖片相關操作(重繪、獲取尺寸、調整大小、縮放)
- jQuery實現(xiàn)的鼠標滾輪控制圖片縮放功能實例
- jQuery圖片縮放插件smartZoom使用實例詳解
- JQuery 圖片延遲加載并等比縮放插件
- jQuery圖片預加載 等比縮放實現(xiàn)代碼
- 基于jquery的防止大圖片撐破頁面的實現(xiàn)代碼(立即縮放)
- jQuery實現(xiàn)的移動端圖片縮放功能組件示例
相關文章
jQuery實現(xiàn)移動端下拉展現(xiàn)新的內容回彈動畫
這篇文章主要介紹了jQuery實現(xiàn)移動端下拉展現(xiàn)新的內容回彈動畫,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-06-06picLazyLoad 實現(xiàn)圖片延時加載(包含背景圖片)
下面小編就為大家?guī)硪黄猵icLazyLoad 實現(xiàn)圖片延時加載(包含背景圖片)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-07-07詳解JavaScript for循環(huán)中發(fā)送AJAX請求問題
這篇文章主要為大家剖析了JavaScript for循環(huán)中發(fā)送AJAX請求問題,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-03-03jQuery實現(xiàn)的網(wǎng)頁左側在線客服效果代碼
這篇文章主要介紹了jQuery實現(xiàn)的網(wǎng)頁左側在線客服效果代碼,涉及簡單的jQuery頁面動畫顯示與隱藏效果實現(xiàn)技巧,非常具有實用價值,需要的朋友可以參考下2015-10-10