Py学习  »  Jquery

jquery delay和get php变量

Rade • 4 年前 • 141 次点击  

我对jquery有一些问题。 我有运行正常的代码,但我想在这两个函数上添加一些延迟(淡入等)。

$(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');
    });
});

我试过了

$(".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);

但出于某种原因,这行不通。我不知道为什么。所以在这里,当它必须添加类时,我需要淡入/延迟/“处理时间”,并且我已经尝试了 .fadeIn("slow")

第二个问题是,我的模板中有一个表,当鼠标悬停在表上时(见jquery函数),它将打开我编写的每个类(rade-test-div2和rade-test2),当我添加.first()时,它只是第一个ofc。我怎样才能只打开我的鼠标在哪里? product item类在表的tr元素中,因此我可以添加如下内容

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

但是如何在jquery中写入来选择这个$uniqueid?我的jquery代码在另一个文件中。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/38187
 
141 次点击  
文章 [ 1 ]  |  最新文章 4 年前
molibdenowy
Reply   •   1 楼
molibdenowy    5 年前
  1. 要制作动画,请使用CSS“Transition”属性: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions . 然后,当一个CSS类被添加到一个元素中时,动画将被触发。
  2. 要操作活动元件,请使用“this”,例如:

$(".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);

例子: https://jsfiddle.net/8vjmhztr/2/