jquery滚动鼠标实现放大缩小图片效果

发布时间:2020-10-26编辑:脚本学堂
如果用jquery实现滚动鼠标即可放大或缩小图片的效果,不用onmousewheel,使用自创的方法支持ie浏览器、火狐浏览器等,实际图片缩放效果,需要的朋友参考下。

基于jquery滚动鼠标放大缩小图片效果

jquey 实现鼠标滚动放大缩小图片的功能,这里不使用onmousewheel,即支持IE浏览器,也支持火狐,使用火狐对应的DOMMouseScroll来处理此功能。

代码:
 

复制代码 代码示例:
$(function(){
$(".body img").each(function(){
if($.browser.msie){
$(this).bind("mousewheel",function(e){
var e=e||event,v=e.wheelDelta||e.detail;
if(v>0)
resizeImg(this,false);//放大图片呗
else
resizeImg(this,true);//缩小图片喽
window.event.returnValue = false;//去掉浏览器默认滚动事件
//e.stopPropagation();
return false;
})
}else{
$(this).bind("DOMMouseScroll",function(event){
if(event.detail<0)
resizeImg(this,false);
else
resizeImg(this,true);
event.preventDefault()//去掉浏览器默认滚动事件
// www.osxue.com
//event.stopPropagation(); })
}
});
function resizeImg(node,isSmall){
if(!isSmall){
$(node).height($(node).height()*1.2);
}else
{
$(node).height($(node).height()*0.8);
}
}
});