Jquery、CSS DIV、Switch 语句

发布于 2024-11-26 11:05:45 字数 3988 浏览 0 评论 0原文

使用 jQuery -

我有

4 个 div - div1、div2、div3 和 div3。分区4 - 当滚动的唯一文本和图像显示到一个名为 div5 的单独 div 中时,内容将取决于您滚动的 div...

我正在考虑使用 switch 语句,但不确定如何传递divs 通过开关盒...??

  • 我还希望动画能够停止()。为当前动画设置动画,并在四个 div 中的任何一个滚动时开始新的动画。??

  • 我还想在四个 div 上有一个单击功能,关闭鼠标悬停效果,并且仅当其他四个 div 之一滚动或单击时才会更改...??

这是我到目前为止所想出的......基本上是单独的动画效果,将它们全部组合在一起有点困难......?

// HTML ----

<div id="maincolumn">   
<div id="js_bg">
    <div class="rollOversHolder">
        <div class="triggerFirstJsSpacer"></div>
        <div class="mainManaged"></div>
        <div class="triggerJsSpacer"></div>
        <div class="mainSolutions"></div>
        <div class="triggerJsSpacer"></div>
        <div class="mainCloud"></div>
        <div class="triggerJsSpacer"></div>
        <div class="mainLicense"></div>
    </div>
    <div class="jsCopysHolder">
        <div class="copy1Holder">
            <div class="leftCopy1">
                Test text _01
            </div>
            <div class="leftCopy2">
                Test text _02
            </div>
            <div class="leftCopy3">
                Test text _03
            </div>
            <div class="leftCopy4">
                Test text _04
            </div>
        </div>
        <div class="copy2Holder">
            <div class="copy1">
            </div>
        </div>
    </div>
</div>

/*CSS ----*/

.main1{
background:url(../images/it_sol_norm.png);
width:103px;
height:133px;
float:left;

.main2 {
background:url(../images/it_sol_norm.png);
width:103px;
height:133px;
float:left;

.main3 {
background:url(../images/it_sol_norm.png);
width:103px;
height:133px;
float:left;

.main4 {
background:url(../images/it_sol_norm.png);
width:103px;
height:133px;
float:left;

.triggerFirstJsSpacer {
width:45px;
height:133px;
float:left;

.triggerJsSpacer  {
width:70px;
height:133px;
float:left;

jsCopysHolder {
width:682px;
height:230px;
border:#CCCCCC 1px solid;
float:left;
font-size:.9em;
color::#5A5A5A;
margin-top:37px;
margin-left:15px;

copy1Holder {
width:330px;
height:150px;
float:left;

.copy2Holder {
width:330px;
height:150px;
float:left;

.leftCopy1 {
width:230px;
height:auto;
display:none;
position:relative;
color:#4d4d4d;

.leftCopy2 {
width:230px;
height:auto;
display:none;
position:relative;
color:#00FF00;

.leftCopy3 {
width:230px;
height:auto;
display:none;
position:relative;
color:#0099FF;

.leftCopy4 {
width:230px;
height:auto;
display:none;
position:relative;
color:#FF0000;




    //jQuery ----

jQuery(".main1").mouseover(function() {
    if (jQuery(".leftCopy1").is(":hidden")) {
        jQuery(".leftCopy1").slideDown("medium");
    }
});

jQuery(".main1").mouseout(function() {
    if (jQuery(".leftCopy1").is(":visible")) {
        jQuery(".leftCopy1").slideUp("medium");
    }
});

jQuery(".main2").mouseover(function() {
    if (jQuery(".leftCopy2").is(":hidden")) {
        jQuery(".leftCopy2").slideDown("medium");
    }
});

jQuery(".main2").mouseout(function() {
    if (jQuery(".leftCopy2").is(":visible")) {
        jQuery(".leftCopy2").slideUp("medium");
    }
});

jQuery(".main3").mouseover(function() {
    if (jQuery(".leftCopy3").is(":hidden")) {
        jQuery(".leftCopy3").slideDown("medium");
    }
});

jQuery(".main3").mouseout(function() {
    if (jQuery(".leftCopy3").is(":visible")) {
        jQuery(".leftCopy3").slideUp("medium");
    }
});

jQuery(".mainLicense").stop().mouseover(function() {
    if (jQuery(".leftCopy4").is(":hidden")) {
        jQuery(".leftCopy4").slideDown("medium");
    }
});

jQuery(".mainLicense").stop().mouseout(function() {
    if (jQuery(".leftCopy4").is(":visible")) {
        jQuery(".leftCopy4").slideUp("medium");
    }
});

Using jQuery -

I have

I have 4 div's - div1, div2, div3 & div4
- that when rolled-over unique text and images are displayed into a separate div called div5, content will depend on what div you have rolled-over...

I was thinking of using a switch statement, but am not sure how to pass the divs through the switch cases...??

  • I would also like the animations to .stop(). animating the current animation and begin the new one when any of the four divs are rolled over.. ??

  • I would also like to have a click function on the four divs that turns off the mouseout rollOver effect and will only change when one of the other four divs is rolled-over or clicked...??

here is what I have come up with so far.. basically individual animation effects, having a bit of trouble tying them all in together...??

// HTML ----

<div id="maincolumn">   
<div id="js_bg">
    <div class="rollOversHolder">
        <div class="triggerFirstJsSpacer"></div>
        <div class="mainManaged"></div>
        <div class="triggerJsSpacer"></div>
        <div class="mainSolutions"></div>
        <div class="triggerJsSpacer"></div>
        <div class="mainCloud"></div>
        <div class="triggerJsSpacer"></div>
        <div class="mainLicense"></div>
    </div>
    <div class="jsCopysHolder">
        <div class="copy1Holder">
            <div class="leftCopy1">
                Test text _01
            </div>
            <div class="leftCopy2">
                Test text _02
            </div>
            <div class="leftCopy3">
                Test text _03
            </div>
            <div class="leftCopy4">
                Test text _04
            </div>
        </div>
        <div class="copy2Holder">
            <div class="copy1">
            </div>
        </div>
    </div>
</div>

/*CSS ----*/

.main1{
background:url(../images/it_sol_norm.png);
width:103px;
height:133px;
float:left;

.main2 {
background:url(../images/it_sol_norm.png);
width:103px;
height:133px;
float:left;

.main3 {
background:url(../images/it_sol_norm.png);
width:103px;
height:133px;
float:left;

.main4 {
background:url(../images/it_sol_norm.png);
width:103px;
height:133px;
float:left;

.triggerFirstJsSpacer {
width:45px;
height:133px;
float:left;

.triggerJsSpacer  {
width:70px;
height:133px;
float:left;

jsCopysHolder {
width:682px;
height:230px;
border:#CCCCCC 1px solid;
float:left;
font-size:.9em;
color::#5A5A5A;
margin-top:37px;
margin-left:15px;

copy1Holder {
width:330px;
height:150px;
float:left;

.copy2Holder {
width:330px;
height:150px;
float:left;

.leftCopy1 {
width:230px;
height:auto;
display:none;
position:relative;
color:#4d4d4d;

.leftCopy2 {
width:230px;
height:auto;
display:none;
position:relative;
color:#00FF00;

.leftCopy3 {
width:230px;
height:auto;
display:none;
position:relative;
color:#0099FF;

.leftCopy4 {
width:230px;
height:auto;
display:none;
position:relative;
color:#FF0000;




    //jQuery ----

jQuery(".main1").mouseover(function() {
    if (jQuery(".leftCopy1").is(":hidden")) {
        jQuery(".leftCopy1").slideDown("medium");
    }
});

jQuery(".main1").mouseout(function() {
    if (jQuery(".leftCopy1").is(":visible")) {
        jQuery(".leftCopy1").slideUp("medium");
    }
});

jQuery(".main2").mouseover(function() {
    if (jQuery(".leftCopy2").is(":hidden")) {
        jQuery(".leftCopy2").slideDown("medium");
    }
});

jQuery(".main2").mouseout(function() {
    if (jQuery(".leftCopy2").is(":visible")) {
        jQuery(".leftCopy2").slideUp("medium");
    }
});

jQuery(".main3").mouseover(function() {
    if (jQuery(".leftCopy3").is(":hidden")) {
        jQuery(".leftCopy3").slideDown("medium");
    }
});

jQuery(".main3").mouseout(function() {
    if (jQuery(".leftCopy3").is(":visible")) {
        jQuery(".leftCopy3").slideUp("medium");
    }
});

jQuery(".mainLicense").stop().mouseover(function() {
    if (jQuery(".leftCopy4").is(":hidden")) {
        jQuery(".leftCopy4").slideDown("medium");
    }
});

jQuery(".mainLicense").stop().mouseout(function() {
    if (jQuery(".leftCopy4").is(":visible")) {
        jQuery(".leftCopy4").slideUp("medium");
    }
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半仙 2024-12-03 11:05:45

您只需通过一个类为 div 创建处理程序:

$('.div_class').hover(function(){
    //stop all animation
    $('.div_class').stop();

    //animate the current one
    $(this).animate(options);
}).click(function(){
    //not sure what you want on click....
});

You would just have to create handlers for the divs through a class:

$('.div_class').hover(function(){
    //stop all animation
    $('.div_class').stop();

    //animate the current one
    $(this).animate(options);
}).click(function(){
    //not sure what you want on click....
});
Oo萌小芽oO 2024-12-03 11:05:45

试试这个

var lastDiv;
$("#div1, #div2, #div3, #div4").hover(function(){
  lastDiv = $(this);

 $(this).animate({});//Pass the animation properties

 $("#div5").html("Set the required text");
  //You can access the rolled over div using $(this)

}, function(){
  $(this).stop();
}).click(function(){
  if(lastDiv)
    lastDiv.stop();

});

Try this

var lastDiv;
$("#div1, #div2, #div3, #div4").hover(function(){
  lastDiv = $(this);

 $(this).animate({});//Pass the animation properties

 $("#div5").html("Set the required text");
  //You can access the rolled over div using $(this)

}, function(){
  $(this).stop();
}).click(function(){
  if(lastDiv)
    lastDiv.stop();

});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文