Shadowing Posted August 7, 2012 Share Posted August 7, 2012 Hey guys I"m trying to edit someones plug in and im having a problemI need to prevent the appendTo from happening more then once what this plug in does is it has a div follow your mouse cursorbut the problem i have with it is if i move the mouse to fast to the right it was making the div be removed so i exit out the remove "preview" but now i cant prevent it from conintuing apending the id previewone thing that did work was using $('#preview').html(''); before it so it clears it first but it caused lag to happend. (function($) { $.fn.trackStar = function(options) { debug(this); var opts = $.extend({}, $.fn.trackStar.defaults, options); return this.each(function() { $this = $(this); var o = $.meta ? $.extend({}, opts, $this.data()) : opts; $this.hover(function(event) { $('body').append('<div id="preview" style="z-index:800; position: absolute;"></div>'); $('#' + opts.displayID).clone().css('id', '').appendTo($('#preview')).show(0); } $('#preview') .css('top', (event.pageY - opts.xOffset) + 'px') .css('left', (event.pageX + opts.yOffset) + 'px') .fadeIn('fast'); }, function(event) { //$('#preview').remove(); }); $this.mousemove(function(event) { $('#preview') .css('top', (event.pageY - opts.xOffset) + 'px') .css('left', (event.pageX + opts.yOffset) + 'px'); }); }); }; function debug($obj) { if (window.console && window.console.log) { ;//console.log(); } }; // plug-in defaults $.fn.trackStar.defaults = { xOffset: 10, yOffset: 30 };})(jQuery); Link to comment Share on other sites More sharing options...
dsonesuk Posted August 7, 2012 Share Posted August 7, 2012 ??? what if you check to see if it already exists, this might work if($("#preview").index()==-1) //only proceed if no id preview element already exists {} Link to comment Share on other sites More sharing options...
Shadowing Posted August 7, 2012 Author Share Posted August 7, 2012 thanks for the responce dsonesuk . ya that was the first thing I tried so i googled how to check for a element that exist but they said to check its lenght which didnt work I'll try your way out Link to comment Share on other sites More sharing options...
Shadowing Posted August 7, 2012 Author Share Posted August 7, 2012 (edited) nice ya that worked. It made it alot smoother now but damn there is still lag. The problem happends when i move the mouse to the right really fast the mouse catches up to the picture that is following the mouse. But I believe the problem is cause the mouse is leaving the area when it hovers on top of the picture following the mouse so I need to figure out how to make it ignore it when it hovers on top of the picture Edited August 7, 2012 by Shadowing Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now