首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从显示在另一个div中的div中动画内容

从显示在另一个div中的div中动画内容
EN

Stack Overflow用户
提问于 2017-04-18 02:50:29
回答 2查看 45关注 0票数 0

jquery非常新,所以任何帮助都会对它表示赞赏。

试图解决设计难题。在第三个元素悬停时,我需要在另一个div中显示来自div的内容。找到了一些代码,帮助我把它放在一起,但我想知道是否有一种方法来动画(滑动,fadein,等等)。显示时的内容。

知道当.html函数显示内容时如何将动画应用到它吗?

代码语言:javascript
复制
var divContent = $("#explore-agility-content").html('');
$( ".industry" ).hover(
    function() {
        $("#explore-agility-content").html( $( this).find("#shortdesc").html() );
    }, 
    function() {
        $("#explore-agility-content").html( divContent );
    }
);

https://jsfiddle.net/rnwebdesigner/3wyrwd92/71/

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-04-18 04:35:26

下面是fadeIn fadeOut对悬停和鼠标悬停的影响

检查一下这把小提琴

https://jsfiddle.net/parthjasani/3wyrwd92/72/

代码语言:javascript
复制
var divContent = $("#explore-agility-content").html('');
$(".industry").hover(

    function () {
        $("#explore-agility-content").html($(this).find("#shortdesc").html());
        $("#explore-agility-content .wb").hide().fadeIn()
    },

    function () {
        $("#explore-agility-content .wb").fadeOut(function () {
            $("#explore-agility-content").html(divContent);
        })
    }

);
票数 0
EN

Stack Overflow用户

发布于 2017-04-18 03:10:39

您可以添加和删除css类,这些类可以包含要在鼠标输入和离开时转换的几个属性。

参见下面的片段(解决方案1)

代码语言:javascript
复制
$('.image').mouseenter(function(){
        $(".text").addClass("animate")
});
$('.image').mouseleave(function(){
            $(".text").removeClass("animate")
});
代码语言:javascript
复制
.image {
    width: 50px;
    height: 50px;
    display: block;
    background-color: red;
    
}
.text {
    background-color: white;
    padding:40px;
       transition:all 0.5s;
}

.left {
        display:block;
        height:400px;
        width: 400px;
        background: url('http://i.stack.imgur.com/jGlzr.png') no-repeat 0 0 scroll;
    background-color:#0C0C0C;
    background-size: 100% 100%;
        }
 .animate{
   
   opacity:1 !important;
   padding-top:50px;

 }
 .noanimate{
   opacity:0;
   padding-top:-50px
   
 }
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="image"></div>
<div class="left">
          <div class="text noanimate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tincidunt consequat tristique. Curabitur vestibulum semper nulla id ornare.
          </div>

</div>

解决方案2-使用悬停函数代替挂载器和离开

代码语言:javascript
复制
$('.image').hover(function(){
        $(".text").toggleClass("animate")
});
代码语言:javascript
复制
.image {
    width: 50px;
    height: 50px;
    display: block;
    background-color: red;
    
}
.text {
    background-color: white;
    padding:40px;
       transition:all 0.5s;
}

.left {
        display:block;
        height:400px;
        width: 400px;
        background: url('http://i.stack.imgur.com/jGlzr.png') no-repeat 0 0 scroll;
    background-color:#0C0C0C;
    background-size: 100% 100%;
        }
 .animate{
   
   opacity:1 !important;
   padding-top:50px;

 }
 .noanimate{
   opacity:0;
   padding-top:-50px
   
 }
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="image"></div>
<div class="left">
          <div class="text noanimate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tincidunt consequat tristique. Curabitur vestibulum semper nulla id ornare.
          </div>

</div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43462771

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档