Показать сообщение отдельно
  #7 (permalink)  
Старый 21.02.2016, 11:58
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,121

fadeIn fadeOut на чистом js
s24344,
<!doctype html>
<html>
<head>

<style>

	.wrapper{
			max-width: 1278px;
			margin: 40px auto;
			line-height: 140%;
		}
		.clearfix:before, .clearfix:after{
			content: " ";
			display: table;
		}
		.clearfix:after{
			clear: both;
		}
		.hover {
			float: left;
		}
		.show {
			float: left;
			width: 400px;
			background-color: #f6f6f6;
			padding: 10px;
			float: left;
			margin-left: 40px;
			display: none;
		}


</style>

</head>

<body>

<div class="wrapper clearfix">
		<div class="hover"><a class="hover__link" href="#">Lorem ipsum</a></div>
		<div class="show"><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eum excepturi voluptatem expedita ipsa totam tenetur corporis at. Officia voluptates impedit sed, dicta laborum aliquid aut dolorem natus. A, veritatis alias.</p></div>
	</div>


<script>


window.requestAnimationFrame = window.requestAnimationFrame
                               || window.mozRequestAnimationFrame
                               || window.webkitRequestAnimationFrame
                               || window.msRequestAnimationFrame
                               || function(f){return setTimeout(f, 1000/60)}

window.cancelAnimationFrame = window.cancelAnimationFrame
                              || window.mozCancelAnimationFrame
                              || function(requestID){clearTimeout(requestID)} //fall back


var requestframeref;
var hover = document.querySelector('.hover');
var show = document.querySelector('.show');
var opacity = 0;
var timestart;
function fadeIn(){
		opacity += 2
		if (opacity > 100){
			opacity = 100;
		}

	else{
    requestframeref = requestAnimationFrame(fadeIn)
	}
	show.style.opacity = opacity/100;

}
function fadeOut(timestamp){
		if (timestamp - timestart > 300)opacity -= 3;
		if (opacity < 0){
			opacity = 0;
            show.style.display = 'none'
		}

	else{
    requestframeref = requestAnimationFrame(fadeOut)
	}
	show.style.opacity = opacity/100;

}

hover.addEventListener('mouseenter', function(){
    cancelAnimationFrame(requestframeref);
    show.style.display = 'block'
	requestAnimationFrame(fadeIn)
}, false)
show.addEventListener('mouseenter', function(){
    cancelAnimationFrame(requestframeref);
    show.style.display = 'block'
	requestAnimationFrame(fadeIn)
}, false)

hover.addEventListener('mouseleave', function(){
	cancelAnimationFrame(requestframeref);
    timestart = performance.now();
    requestAnimationFrame(fadeOut)
}, false)
show.addEventListener('mouseleave', function(){
	cancelAnimationFrame(requestframeref);
    timestart = performance.now();
    requestAnimationFrame(fadeOut)
}, false)

</script>

</body>
</html>
Ответить с цитированием