我可以銷燬這個函數或mousemove事件嗎?我可以銷燬這個函數或mousemove事件嗎?
我在jQuery中有一些代碼讓我頭疼。我在網上發現了這個代碼,當我傳遞元素時,我服務於鼠標移動效果,但是想知道當我離開他時怎樣才能補充或刪除事件。
一個例子,我有如下:
$("#icons").mouseenter(function(e) {
$(this).find('div').slidemouse();
});
$("#icons").mouseleave(function(e) {
$(this).find('div').slidemouse('destroy');
});
代碼插件:
(function($) {
$.fn.slidemouse=function(options) {
var defaults=
{
height:'240px',
widthExpand:true,
mirror:false,
mirrorOpacity:.3
};
var opts=$.extend(defaults,options);
var expands=1;
var galleryWidth=0;
var self=this;
self.css('overflow','hidden');
self.children().css('height',opts.height);
self.children().children().each(function(index) {
galleryWidth=galleryWidth+$(this).outerWidth(true)
}
);
if(opts.widthExpand) {
while(galleryWidth<self.width()) {
self.children().children(":nth-child("+expands+")").clone().appendTo(self.children());
galleryWidth=galleryWidth+self.children().children(":nth-child("+expands+")").outerWidth(true);
expands++
}
}
self.children().css("width",galleryWidth);
if(opts.mirror) {
self.clone().insertAfter(self).attr("id","");
self.next().fadeTo(0,opts.mirrorOpacity)
}
if(opts.widthExpand||opts.mirror) {
$(window).bind("resize",resizeWindow)
}
function resizeWindow() {
if(opts.widthExpand) {
galleryWidth=0;
self.children().children().each(function(index) {
galleryWidth=galleryWidth+$(this).outerWidth(true)
});
while(galleryWidth<self.width()) {
self.children().children(":nth-child("+expands+")").clone().appendTo(self.children());
galleryWidth=galleryWidth+self.children().children(":nth-child("+expands+")").outerWidth(true);
expands++
}
self.children().css("width",galleryWidth);
if(opts.mirror) {
self.next().remove();
self.clone().insertAfter(self).attr("id","");
self.next().fadeTo(0,opts.mirrorOpacity)
}
}
}
$(this).parent().mousemove(function(e) {
var x=e.pageX-this.offsetLeft;
var calc=(self.children().width()-self.width())/self.width();
var left=x*calc;
var right=(self.width()-x)*calc;
self.stop().animate({scrollLeft: left}, 500);
if(opts.mirror) {
self.next().stop().animate({scrollLeft: right}, 500);
}
})
}
}
)(jQuery);
我恐怕這裏的前兩段在英文中沒有太大意義。你會編輯你的問題來解釋一下這個問題,或者讓別人來幫助你改正它嗎?目前尚不清楚問題是什麼。 – halfer
如果你原諒我的英語,因爲我講西班牙語 –