Video Player
00:00
00:00
マウスの座標軸を$(‘#container’).mousemove(function(e){ console.log(e.clientX, e.clientY); で取得し、中心からの距離に合わせてオブジェクトの形状を変える処理です。
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 | <! DOCTYPE html> < html lang = "ja" > < head > < meta charset = "utf-8" > < meta name = "viewport" content = "width=device-width, initial-scale=1.0" > < title >パララックスサイト</ title > < style > body { margin: 0; padding: 0; } #container { width: 600px; height: 280px; background: #eee; } .box { position: fixed; opacity: 0.6; left: 300px; } #box1 { width: 40px; height: 40px; top: 140px; background: red; } #box2 { width: 50px; height: 50px; top: 155px; background: blue; } #box3 { width: 60px; height: 60px; top: 165px; background: yellow; } </ style > < link rel = "stylesheet" href = "styles.css" > </ head > < body > < div id = "container" > < div id = "box1" class = "box" ></ div > < div id = "box2" class = "box" ></ div > < div id = "box3" class = "box" ></ div > </ div > < script > $(function(){ $('#container').mousemove(function(e){ console.log(e.clientX, e.clientY); var cx = $(this).width() / 2; var cy = $(this).height() / 2; var dx = e.clientX - cx; var dy = e.clientY - cy; $('#box1').css('left', cx + dx * 1.1); $('#box2').css('left', cx + dx * 1.3); $('#box3').css('left', cx + dx * 1.5); $('#box1').css('top', cy + dy * 1.0); $('#box2').css('top', cy + dy * 1.1); $('#box3').css('top', cy + dy * 1.2); }); }); </ script > </ body > </ html > |