本文介绍了Jquery if else color shuffle(传递一个变量)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是关于我在这个链接上提出的这个问题:



我已经更改并添加了更多代码,并且有一个不同的问题因此我开了一个新主题。



每次刷新页面时,我都会使用php和jQuery对颜色进行随机播放。目前这个工作正常。但我有一个jQuery函数,我抓住一些元素,并在一个hoverstate显示shuffle颜色。现在这确实有效,但它显示了css标准默认的红色,蓝色,绿色等,甚至没有显示橙色的颜色。我被建议创建一个变量,然后创建一个if函数并通过悬停函数传递变量。下面是我到目前为止,我是jQuery的新手用户所以我不确定我哪里出错或下一步去哪里,有人可以指导我为什么这会被打破?我的萤火虫没有显示任何错误,我认为即将到来!谢谢。



PHP随机播放颜色:

 <?php 
$ colors = array('red','green','blue','black');
$ blog = $ colors [array_rand($ colors,1)];
?>

< body id =<?php echo $ blog;?>>

在我的css中,无论我想要显示洗牌颜色#green,#red都在trueallid之前,类或元素,它的工作原理!只是悬停状态现在我有这个jQuery ..



//颜色翻转导航

  var colors =<?php echo $ colors;?>; 


if(colors ==red){
colors =#600;
}
else if(colors ==green){
colors =#363;
}
else if(colors ==blue){
colors =#369;
}
else if(colors ==black){
colors =#000;
}

//使用悬停效果的一些元素的示例
$(#footer .address #breadcrumbs a)。hover(function(){
$(this).stop()。animate({'color':colors},300);
},function(){
$(this).stop()。animate({ 'color':#fff},300);
});

我是否错过了if else中的一些行或者通过错误传递变量?谢谢!

解决方案

好的我工作正常。



我做了一些事情所以不确定究竟是什么彻底修复了它:



-Clear Cache(Google Chrome对此很痛苦)



- 将变量从颜色变为颜色(在php和JS中)



- 在JS中定义变量时,我回显了$ blog而不是$ color。 / p>

我也没有错误。



谢谢!


This is regarding this question i asked on this link:PHP CSS Colour Shuffle array?

I have changed and added more code and have a different question hence why i've opened a new thread.

I am using php and jQuery to shuffle colours every time the page is refreshed. At the moment this works fine. But i have a jQuery function where i grab some elements and on a hoverstate show the shuffle colour. Now this does work but it's showing css standard default red,blue,green ect and not even displaying colours for the orange. I have been advised to create a variable and then create an if function and pass the variable through the hover function. Below is what i have so far, im a novice user at jQuery so i am unsure of where i am going wrong or where to go next, can someone guide me to why this is broken? My firebug shows no errors and i think im nearly there! Thanks.

PHP Shuffle colours:

<?php
$colours = array('red', 'green', 'blue', 'black');
$blog = $colours[array_rand($colours, 1)];
?>

<body id="<?php echo $blog; ?>">

In my css wherever i wanted to show the shuffle colour #green, #red is before the actuallid,class or element and it works! Just the hover states now where i have this jQuery..

// colour rollover navigation

var colours = "<?php echo $colours; ?>";


        if(colours == "red"){
           colours = "#600";
        }
        else if(colours == "green"){
           colours = "#363";
        }
        else if(colours == "blue"){
           colours = "#369";
        }
        else if(colours == "black"){
           colours = "#000";
        }

                    //example of some elements that would use the hover effect
        $("#footer .address #breadcrumbs a").hover(function() {
            $(this).stop().animate({ 'color': colours }, 300);
        },function() {
            $(this).stop().animate({ 'color': "#fff" }, 300);
        });

Am i missing some lines in the if else or passing the variable through wrong? Thanks!

解决方案

Ok i have it working.

I did some things so not sure exactly what totally fixed it:

-Clear Cache (Google Chrome is a pain for this)

-Changed the variable from Colours to color (both in php and JS)

-When defining the variable in JS i echoed $blog instead of $colour.

I get no errors when this works as well.

Thanks!

这篇关于Jquery if else color shuffle(传递一个变量)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 12:25