2017-01-30 79 views
0

我想將摩托車從右邊移到左邊如何在html中移動對象?

enter image description here

在這裏你可以看到摩托車。當頁面完成加載時,我想讓滑板車靠近那位女士坐的那把椅子。

這裏是我的代碼: -

.inner-girl-icon { 
    float: right; 
    margin: 5px 262px; 
    max-width: 75px; 
    width: 100%; 
} 
<div class="col-md-8 col-sm-8 col-xs-12"> 
    <div class="girl-icon"> 
    <span class="inner-girl-salon"><img src="{{ asset('images/demo/salon-icon.png') }}" class="img-responsive"></span> 
    </div> 
    <div class="girl-icon"> 
    <span class="inner-girl-icon"><img src="{{ asset('images/demo/demo1.jpg') }}" class="img-responsive"></span> 
    </div> 
</div> 
+1

https://www.google.com/search?q=animate+move+one+div+closer+to+another – mplungjan

+0

HTTP: //stackoverflow.com/a/41563719/4206079 – Banzay

回答

2

您可以在CSS3中添加animation,這些人將滑板車元素移到椅子旁邊。

With Jqueryready event中加入你的動畫class

$(document).ready(function(){ 
 
    $(".scooter").addClass("animon"); 
 
});
.container{ 
 
    position:relative; 
 
} 
 

 
.chair{ 
 
    position:absolute; 
 
    left:50px; 
 
    background-color:blue; 
 
    width:40px; 
 
    height:40px; 
 
} 
 

 
.scooter{ 
 
    position:absolute; 
 
    left:400px; 
 
    background-color:green; 
 
    width:40px; 
 
    height:40px; 
 
} 
 

 
.animon{ 
 
    animation:animscooter 2s ease-out forwards; 
 
} 
 

 
@keyframes animscooter{ 
 
    0%{ 
 
    left:400px; 
 
    } 
 
    100%{ 
 
    left:90px; 
 
    } 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="container"> 
 
    <div class="chair"> 
 
    </div> 
 
    <div class="scooter"> 
 
    </div> 
 
</div>

+0

這是一個很好的例子 –

1

試試這個代碼

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<style> 
 
div { 
 
    width: 100px; 
 
    height: 100px; 
 
    background: yellow; 
 
    position: relative; 
 
    -webkit-animation: myfirst 5s infinite; /* Safari 4.0 - 8.0 */ 
 
    -webkit-animation-direction: alternate; /* Safari 4.0 - 8.0 */ 
 
    animation: myfirst 5s 3s; 
 
    animation-direction: alternate; 
 
} 
 

 
/* Safari 4.0 - 8.0 */ 
 
@-webkit-keyframes myfirst { 
 
    25% {background: yellow; left: 200px; top: 0px;} 
 
} 
 

 
@keyframes myfirst { 
 
    25% {background: yellow; left: 200px; top: 0px;} 
 
} 
 
</style> 
 
</head> 
 
<body> 
 

 
<div></div> 
 

 

 
</body> 
 
</html>

改變你的方向按您的要求

0

下面是一個工作示例,這關注容器div,它是通過繼承改變一些HTML的兒童,以及用它的個人CSS設置爲其設置ID的「滑板車」。

2秒鐘後,我做了浮動改變。

請看:

// Wait for DOM load 
 
$(document).ready(function() { 
 
    // The element goes left 2 seconds later for example 
 
    setTimeout(function() { 
 
    // Changing the CSS attribute 
 
    $('#scooter').css('float', 'left'); 
 
    // Console message 
 
    console.log('changed!'); 
 
    }, 2000); 
 
});
/* Instead of margin in girl-icon i'm setting default width to both containers */ 
 
.girl-icon { 
 
    width: 100px; 
 
    float: left; 
 
} 
 

 
/* Scooter default CSS */ 
 
#scooter { 
 
    float: right; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="col-md-8 col-sm-8 col-xs-12"> 
 
<div class="girl-icon"> 
 
    <!-- Converted to div --> 
 
    <div class="inner-girl-salon"> 
 
    <!-- Represents the 1st image --> 
 
    <div id="person">person</div> 
 
    </div> 
 
    <!-- Clear both --> 
 
    <div style="clear:both"></div> 
 
</div> 
 
<div class="girl-icon"> 
 
    <!-- Converted to div --> 
 
    <div class="inner-girl-icon"> 
 
    <!-- Represents the 2nd image --> 
 
    <div id="scooter">scooter</div> 
 
    </div> 
 
    <!-- Clear both --> 
 
    <div style="clear:both"></div> 
 
</div> 
 

 
<!-- Clear both --> 
 
<div style="clear:both"></div>