简体   繁体   中英

jQuery conflict with an plugin?

I had an blog using WordPress. I got an jQuery code to make some div fixed after some scroll, got it here: http://jqueryfordesigners.com/fixed-floating-elements/

Someday ago, I got an plugin to make and "Recent Post Slider" for WordPress. But when I activate it, the fixed div jQuery stop working. I think that can be an conflict, but really don't have sure yet.

What is the best move to know what's happening?

You can use jQuery.noconflict() for this. For example:

$j = jQuery.noConflict();
$j("your_div").css("position", "fixed");

Here you have the code explanation. jQuery.noConflict

Get a browser with JavaScript debugger console and make it print you the $ variable. jQuery returns : function (a,b){return new e.fn.init(a,b,h)} . The $ variable is sometimes used by other libraries, and if you use it directly in your jQuery it may get overwritten. To avoid this, encapsulate your jQuery code:

(function($) {
  your code with $
})(jQuery)

This may break some of your global variables though, it depends on how you wrote your code.

I don't think that jQuery does not work anymore as @nicowernli said. But it is possible that the plugin changed the html of the page.

The best move is to disable the "Recent Post Slider" plugin and check if the fix starts working again. Then you will know what where problem is.

确保已包含一次Jquery,但不再重复

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM