douji8549 2018-10-12 10:25
浏览 72

jQuery延迟并获取php变量

I have some problems with jQuery. I have code that is running ok, but I want to add some delay (fade in, etc...) on this both functions.

$(document).ready(function(){
    $(".product-item, .rade-test").mouseover(function(){
        $('.just-to-define').removeClass('rade-test-div');
        $('.just-to-define').addClass('rade-test-div2');
        $('.heredefine').removeClass('rade-test');
        $('.heredefine').addClass('rade-test2');
    });
    $( ".product-item, .rade-test" ).mouseout(function() {
        $('.just-to-define').addClass('rade-test-div');
        $('.just-to-define').removeClass('rade-test-div2');
        $('.heredefine').addClass('rade-test');
        $('.heredefine').removeClass('rade-test2');
    });
});

I tried with

$(".product-item, .rade-test").mouseover(function(){
        $('.just-to-define').removeClass('rade-test-div');
        $('.just-to-define').addClass('rade-test-div2');
        $('.heredefine').removeClass('rade-test');
        $('.heredefine').addClass('rade-test2');
    }, 2000);

but that's not working from some reason. I don't know why. So here when it have to add class i need fade in/delay/'process time', and i already tried with .fadeIn("slow")

Second what I have problem with this is, I have table foreached in my template, and when mouse is over table (see in jQuery function) it's opening every class that i have write (rade-test-div2 and rade-test2), and when I add .first() it's only first ofc. How can I open only table where is my mouse? product-item class is in TR element of table, so I can add something like

@php $uniqueId = uniqId(); @endphp
<tr class="product-item {{$uniqueId}}">

But how to write in jQuery to select this $uniqueId? My jQuery code is in another file.

  • 写回答

1条回答 默认 最新

  • duanpa2143 2018-10-12 10:37
    关注
    1. To make an animation, use a CSS "transition" property: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions. Then, when a CSS class will be added to an element, the animation will be triggered.
    2. To manipulate the active element use "this", e.g.:

    $(".product-item, .rade-test").mouseover(function(){
        var $this = $(this);
    
        $this.find('.just-to-define').removeClass('rade-test-div');
        $this.find('.just-to-define').addClass('rade-test-div2');
        $this.find('.heredefine').removeClass('rade-test');
        $this.find('.heredefine').addClass('rade-test2');
    }, 2000);

    Example: https://jsfiddle.net/8vjmhztr/2/

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)