{"id":41,"date":"2015-03-23T14:35:39","date_gmt":"2015-03-23T05:35:39","guid":{"rendered":"http:\/\/www.takaya-com.jp\/archives\/?p=41"},"modified":"2015-03-23T14:35:39","modified_gmt":"2015-03-23T05:35:39","slug":"hover_anime","status":"publish","type":"post","link":"https:\/\/takaya-com.jp\/archives\/2015\/03\/hover_anime\/","title":{"rendered":"\u30de\u30a6\u30b9\u30ab\u30fc\u30bd\u30eb\u306e\u51fa\u5165\u308a\u306e\u65b9\u5411\u3067\u5909\u308f\u308b\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3"},"content":{"rendered":"<p><b>\u30de\u30a6\u30b9\u30ab\u30fc\u30bd\u30eb\u306e\u51fa\u5165\u308a\u306e\u65b9\u5411<\/b>\u3067<b>\u8868\u793a\u3001\u52d5\u304d\u3092\u5909\u3048\u308b<\/b>\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3067\u3059\u3002<br \/>\n\u30ab\u30fc\u30bd\u30eb\u306e\u5165\u308b\u65b9\u5411\u3067\u8272\u304c\u5909\u308f\u308a\u3001\u51fa\u305f\u65b9\u5411\u306b\u52d5\u304d\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306fCSS\u3067\u8272\u3092\u3064\u3051\u3066\u3044\u307e\u3059\u304c\u3001background\u306b\u753b\u50cf\u3092\u6307\u5b9a\u3059\u308b\u65b9\u6cd5\u3067\u3082\u53ef\u80fd\u3067\u3059\u3002<br \/>\n\u30a2\u30a4\u30b3\u30f3\u306a\u3069\u306e\u30de\u30a6\u30b9\u30aa\u30fc\u30d0\u30fc\u306b\u5909\u5316\u3092\u3064\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u25bc\u4ee5\u4e0b\u304c\u5b9f\u969b\u306e\u30bd\u30fc\u30b9\u30b5\u30f3\u30d7\u30eb\u3067\u3059\u3002<\/p>\n<pre class=\"lang:js decode:true \" title=\"JavaScript\" >$( function() {\r\n\r\n\tvar Enter = function( e ) {\r\n\r\n\t\tvar Hover = e.type === 'mouseenter',\r\n\r\n\t\t$box = $( this ),\r\n\t\t$overlay = $( '#overlay', $box ),\r\n\t\toverlayW = $overlay.width(),\r\n\t\tmouseX = e.clientX - ($box.offset().left + overlayW \/ 2),\r\n\t\tmouseY = e.clientY - ($box.offset().top + overlayW \/ 2),\r\n\t\tdegrees = Math.atan2( mouseY, mouseX ) * 180 \/ Math.PI,\r\n\t\tstyle = {};\r\n\r\n\t\tif ( degrees &gt; -135 &amp;&amp; degrees &lt;= -45 ) {\r\n\t\t\tstyle.top = -overlayW;\r\n\t\t\tstyle.left = 0;\r\n\t\t\t$overlay.css('background-color','red')\r\n\t\t} else if ( degrees &gt; -45 &amp;&amp; degrees &lt;= 45 ) {\r\n\t\t\tstyle.top = 0;\r\n\t\t\tstyle.left = overlayW;\r\n\t\t\t$overlay.css('background-color','blue')\t\t\t\r\n\t\t} else if ( degrees &gt; 45 &amp;&amp; degrees &lt;= 135 ) {\r\n\t\t\tstyle.top = overlayW;\r\n\t\t\tstyle.left = 0;\r\n\t\t\t$overlay.css('background-color','green')\r\n\t\t} else {\r\n\t\t\tstyle.top = 0;\r\n\t\t\tstyle.left = -overlayW;\r\n\t\t\t$overlay.css('background-color','yellow')\r\n\t\t}\r\n\r\n\t\t$overlay\r\n\t\t.show()\r\n\t\t.css( {\r\n\t\t\ttop: Hover ? style.top : 0,\r\n\t\t\tleft: Hover ? style.left : 0,\r\n\t\t} )\r\n\t\t.stop( true )\r\n\t\t.animate( {\r\n\t\t\ttop: Hover ? 0 : style.top,\r\n\t\t\tleft: Hover ? 0 : style.left\r\n\t\t}, \"slow\");\r\n\r\n\t};\r\n\t\r\n\tvar Leave = function( e ) {\r\n\r\n\t\tvar Hover = e.type === 'mouseenter',\r\n\r\n\t\t$box = $( this ),\r\n\t\t$overlay = $( '#overlay', $box ),\r\n\t\toverlayW = $overlay.width(),\r\n\t\tmouseX = e.clientX - ($box.offset().left + overlayW \/ 2),\r\n\t\tmouseY = e.clientY - ($box.offset().top + overlayW \/ 2),\r\n\t\tdegrees = Math.atan2( mouseY, mouseX ) * 180 \/ Math.PI,\r\n\t\tstyle = {};\r\n\r\n\t\tif ( degrees &gt; -135 &amp;&amp; degrees &lt;= -45 ) {\r\n\t\t\tstyle.top = -overlayW;\r\n\t\t\tstyle.left = 0;\r\n\t\t} else if ( degrees &gt; -45 &amp;&amp; degrees &lt;= 45 ) {\r\n\t\t\tstyle.top = 0;\r\n\t\t\tstyle.left = overlayW;\r\n\t\t} else if ( degrees &gt; 45 &amp;&amp; degrees &lt;= 135 ) {\r\n\t\t\tstyle.top = overlayW;\r\n\t\t\tstyle.left = 0;\r\n\t\t} else {\r\n\t\t\tstyle.top = 0;\r\n\t\t\tstyle.left = -overlayW;\r\n\t\t}\r\n\r\n\t\t$overlay\r\n\t\t.animate( {\r\n\t\t\ttop: - Hover ? 0 : style.top,\r\n\t\t\tleft: - Hover ? 0 : style.left\r\n\t\t}, \"slow\");\r\n\r\n\t};\r\n\r\n\r\n\t$( '#box' )\r\n\t.on('mouseenter', Enter )\r\n\t.on('mouseleave', Leave );\r\n\r\n\r\n\t});\r\n<\/pre>\n<p>\u56f3\u5f62\u306e\u4e2d\u5fc3\u3092\u57fa\u6e96\u306b\u3057\u3066\u89d2\u5ea6\u3067\u65b9\u5411\u3092\u6307\u5b9a\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u9577\u65b9\u5f62\u306e\u5834\u5408\u306f\u8a08\u7b97\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p>\u25bcCSS<\/p>\n<pre class=\"lang:css decode:true \" title=\"CSS\" >#main {\r\n\twidth:100%;\r\n\tposition: absolute;\r\n}\r\n#box {\r\n\tmargin:200px auto;\r\n\tposition: relative;\r\n\twidth: 200px;\r\n\theight: 200px;\r\n    overflow: hidden;\r\n    background: #333;\r\n}\r\n#overlay {\r\n\tposition: absolute;\r\n\ttop: 200px;\r\n\twidth: 200px;\r\n\theight: 200px;\r\n}\r\n<\/pre>\n<p>\u25bcHTML<\/p>\n<pre class=\"lang:xhtml decode:true \" title=\"HTML\" >&lt;div id=\"main\"&gt;\r\n  &lt;div id=\"box\"&gt;\r\n    &lt;div id=\"overlay\"&gt;&lt;\/div&gt;\r\n  &lt;\/div&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<p>\u4eca\u56de\u3001\u53c2\u8003\u306b\u3055\u305b\u3066\u3044\u305f\u3060\u3044\u305f\u306e\u306f\u3001<br \/>\n\u300e<a href=\"http:\/\/nbnote.jp\/blog\/2012\/12\/anim-overlay\/\">[JS] \u30ab\u30fc\u30bd\u30eb\u9032\u5165\u4f4d\u7f6e\u306b\u5408\u308f\u305b\u3066\u5909\u308f\u308b\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3 &#8211; nbnote blog<\/a>\u300f\u3055\u3093\u3067\u3059\u3002<br \/>\n\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/www.takaya-com.jp\/archives\/demo\/hover_anime\/\" target=\"_blank\">\u30c7\u30e2\u30da\u30fc\u30b8\u306f\u3001\u3053\u3061\u3089<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30de\u30a6\u30b9\u30ab\u30fc\u30bd\u30eb\u306e\u51fa\u5165\u308a\u306e\u65b9\u5411\u3067\u8868\u793a\u3001\u52d5\u304d\u3092\u5909\u3048\u308b\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3067\u3059\u3002 \u30ab\u30fc\u30bd\u30eb\u306e\u5165\u308b\u65b9\u5411\u3067\u8272\u304c\u5909\u308f\u308a\u3001\u51fa\u305f\u65b9\u5411\u306b\u52d5\u304d\u307e\u3059\u3002 \u4eca\u56de\u306fCSS\u3067\u8272\u3092\u3064\u3051\u3066\u3044\u307e\u3059\u304c\u3001background\u306b\u753b\u50cf\u3092\u6307\u5b9a\u3059\u308b\u65b9\u6cd5\u3067\u3082\u53ef\u80fd\u3067\u3059\u3002 \u30a2\u30a4\u30b3 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/posts\/41"}],"collection":[{"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/comments?post=41"}],"version-history":[{"count":1,"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/posts\/41\/revisions"}],"predecessor-version":[{"id":42,"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/posts\/41\/revisions\/42"}],"wp:attachment":[{"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/media?parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/categories?post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/takaya-com.jp\/archives\/wp-json\/wp\/v2\/tags?post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}