-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiblock_parallax_2.js
68 lines (51 loc) · 1.43 KB
/
iblock_parallax_2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(function($){
var window_scroll, block, wwpos, interval, proc, tt;
$(document).ready(function(){
$('.iblock_parallax').css({
position: 'absolute',
zIndex: 1,
top: 0,
left: 0,
opacity: 0,
maxWidth: 'none'
});
});
$(window).on('load',function(){
serv_img_sz();
serv_img_pos();
$('.iblock_parallax').stop().animate({ opacity: 1 }, 500);
});
$(window).scroll(function(){
serv_img_pos();
});
$(window).resize(function(){
serv_img_sz();
serv_img_pos();
});
function serv_img_pos()
{
window_scroll= $(window).scrollTop();
wwpos= ($(window).height()+window_scroll);
$('.iblock_parallax').each(function(){
block= $(this).parent();
if(wwpos>block.offset().top-50 && window_scroll<block.offset().top+block.outerHeight()+50)
{
interval= ($(window).height()+block.outerHeight()) + 100;
proc= wwpos-block.offset().top + 50;
proc= proc * 100 / interval; //console.log(proc);
tt= $(this).height()-block.outerHeight();
tt= tt * proc / 100 * (-1); //console.log(tt);
$(this).css({ top: tt });
}
});
}
function serv_img_sz()
{
$('.iblock_parallax').each(function(){
$(this).css({ width:'auto', height:$(window).height() });
$(this).css({ left:(-1)*($(this).parent().outerWidth()-$(this).width())/2 });
if($(this).width()<$(this).parent().outerWidth())
$(this).css({ width:$(this).parent().outerWidth(), height:'auto', left:0 });
});
}
})(jQuery);