问题描述
首先访问此页面,然后将鼠标悬停在菜单上: http://milabalami.com/saved/2/index.php
First visit this page and hover your mouse over the menu:http://milabalami.com/saved/2/index.php
然后访问此Wordpress页面,在该页面上我实现了完全相同的代码: http://milabalami.com
Then visit this Wordpress page where I have implemented the exact same code:http://milabalami.com
将鼠标悬停在Wordpress菜单上时,您会看到滑块未显示.为什么?我可以看到页面显示错误:
When you hover your mouse over the Wordpress menu, you will see that the slider does not show up. Why? I can see that the page gives an error stating:
$ is not a function
http://miladalami.com/wp-content/themes/sandbox/js/custom.js
那是为什么?它的代码完全相同,可以在另一页上完美地工作.我不明白为什么它会在Wordpress页面上给出该错误,而不是在滑块可以工作的另一页面上给出该错误.有谁可以帮助我解决这个难题?
Why is that? Its the exact same code that worked perfectly on the other page. I dont understand why it is giving that error on the Wordpress page, and not on the other one where the slider works. Anyone that could assist me in solving this puzzle?
益江解决了难题.
推荐答案
在整个过程中,似乎都覆盖了$
.但是,仍然可以使用jQuery
代替$
-
It looks like somewhere along the way, the $
got overridden. You can still use your code, however, by using jQuery
instead of $
-
jQuery(document).ready(function($) {
$("#featured").easySlider({
speed: 400
});
$("#menu ul li a[class!='current']")
.css( {backgroundPosition: "200px 2px"} )
.mouseover(function(){
$(this).stop().animate({backgroundPosition:"(0 2px)"}, {duration:400})
})
.mouseout(function(){
$(this).stop().animate({backgroundPosition:"(200px 2px)"}, {duration:400})
})
});
这是权宜之计.您应该将所有代码组合到一个文件中,而不是像现在这样将它们分开,以减少对插件的依赖.
It's a stopgap measure, however. You should combine all your code into a single file, instead of separating them out like they are right now, and reduce your dependency on plugins.
这篇关于Easyslider的Javascript问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!