jQuery div 旋转器在 Fiddle 但不是 WordPress 网站上工作。尝试了 3 件事
jQuery div rotator working on Fiddle but not WordPress website. Tried 3 things
我正在使用像这样的 jQuery div 旋转器:http://jsfiddle.net/kDSqB 它在 Fiddle 中工作得非常好。当我将相同的代码移到我的 WordPress 网站时,它不起作用。
我试过添加jQuery没有冲突,添加一个DOM文件准备好了,把$(document.body)改成父div的名字。 None 其中有效。
我还尝试将所有相关的 jQuery 内联移动到代码将出现的页面部分,但 div 仍然没有旋转。我该怎么办?
以下是我的 WordPress 网站上的所有代码:
<script src="https://code.jquery.com/jquery-1.10.1.js">
<script type="text/javascript">
jQuery.noConflict();
$(document).ready(function(){
var $cog = $('#cog'),
$body = $(document.body),
bodyHeight = $body.height();
$(window).scroll(function () {
$cog.css({
'transform': 'rotate(' + ($body.scrollTop() / bodyHeight * 360) + 'deg)'
});
});
});
});
</script>
<div class="cogclass"><div id="cog"></div></div>
我查看了控制台错误并发现了这个 post:TypeError: $ is not a function when calling jQuery function。原来这可能是WordPress的东西,我必须把代码放在里面 jQuery(document).ready(function($){ code here ;
所以这段代码最终得到了解决:
<script>
jQuery(document).ready(function($){
var $cog = $('#cog'),
$body = $('body'),
bodyHeight = $body.height();
$(window).scroll(function () {
$cog.css({
'transform': 'rotate(' + ($body.scrollTop() / bodyHeight * 360) + 'deg)'
});
});
});
</script>
感谢所有帮助找到答案的人!
我正在使用像这样的 jQuery div 旋转器:http://jsfiddle.net/kDSqB 它在 Fiddle 中工作得非常好。当我将相同的代码移到我的 WordPress 网站时,它不起作用。
我试过添加jQuery没有冲突,添加一个DOM文件准备好了,把$(document.body)改成父div的名字。 None 其中有效。
我还尝试将所有相关的 jQuery 内联移动到代码将出现的页面部分,但 div 仍然没有旋转。我该怎么办?
以下是我的 WordPress 网站上的所有代码:
<script src="https://code.jquery.com/jquery-1.10.1.js">
<script type="text/javascript">
jQuery.noConflict();
$(document).ready(function(){
var $cog = $('#cog'),
$body = $(document.body),
bodyHeight = $body.height();
$(window).scroll(function () {
$cog.css({
'transform': 'rotate(' + ($body.scrollTop() / bodyHeight * 360) + 'deg)'
});
});
});
});
</script>
<div class="cogclass"><div id="cog"></div></div>
我查看了控制台错误并发现了这个 post:TypeError: $ is not a function when calling jQuery function。原来这可能是WordPress的东西,我必须把代码放在里面 jQuery(document).ready(function($){ code here ;
所以这段代码最终得到了解决:
<script>
jQuery(document).ready(function($){
var $cog = $('#cog'),
$body = $('body'),
bodyHeight = $body.height();
$(window).scroll(function () {
$cog.css({
'transform': 'rotate(' + ($body.scrollTop() / bodyHeight * 360) + 'deg)'
});
});
});
</script>
感谢所有帮助找到答案的人!