<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>javascript on The Official Wireshark Blog</title>
    <link>https://blog.wireshark.org/tags/javascript/</link>
    <description>Recent content in javascript on The Official Wireshark Blog</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Fri, 13 Nov 2009 05:11:26 +0000</lastBuildDate><atom:link href="https://blog.wireshark.org/tags/javascript/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Javascript Background Animation</title>
      <link>https://blog.wireshark.org/2009/11/js-bg-animation/</link>
      <pubDate>Fri, 13 Nov 2009 05:11:26 +0000</pubDate>
      
      <guid>https://blog.wireshark.org/2009/11/js-bg-animation/</guid>
      <description>&lt;p&gt;The Windows 7 taskbar does this nifty little background animation when you mouse over an open application’s icon. I wanted to see if the effect could be duplicated on a web page.&lt;/p&gt;
&lt;p&gt;Suppose we have a couple of inline elements:&lt;/p&gt;
&lt;p&gt;&lt;span style=&#34;color: #000080;&#34;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&amp;lt;div&amp;gt;
  &amp;lt;img class=&#34;bgmove&#34; src=&#34;wsbadge-empty.png&#34;&amp;gt;
&amp;lt;/div&amp;gt;&lt;/pre&gt;
&lt;p&gt;&lt;span style=&#34;color: #000080;&#34;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&amp;lt;h1&amp;gt;
  &amp;lt;span class=&#34;bgmove&#34;&amp;gt;Packets!&amp;lt;/span&amp;gt;
&amp;lt;/h1&amp;gt;&lt;/pre&gt;
&lt;p&gt;The image is mostly transparent:&lt;/p&gt;
&lt;img loading=&#34;lazy&#34; decoding=&#34;async&#34; class=&#34;alignnone size-full wp-image-280&#34; title=&#34;wsbadge-empty&#34; src=&#34;https://blog.wireshark.org/wp-content/uploads/2009/11/wsbadge-empty.png&#34; alt=&#34;wsbadge-empty&#34; width=&#34;186&#34; height=&#34;64&#34; /&gt; 
&lt;p&gt;We have a background that’s slightly larger than our elements, which lets us position it using negative offsets:&lt;/p&gt;
&lt;img loading=&#34;lazy&#34; decoding=&#34;async&#34; class=&#34;alignnone size-full wp-image-281&#34; title=&#34;wsbadge-bg&#34; src=&#34;https://blog.wireshark.org/wp-content/uploads/2009/11/wsbadge-bg.png&#34; alt=&#34;wsbadge-bg&#34; width=&#34;279&#34; height=&#34;95&#34; /&gt; 
&lt;p&gt;&lt;span style=&#34;color: #008000;&#34;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;.bgmove {
  background-image: url(&#39;wsbadge-bg.png&#39;);
  background-repeat: no-repeat;
  background-position: -50px -20px;
}&lt;/pre&gt;
&lt;p&gt;jQuery lets us do two important things: track mouse motion and determine an element’s dimensions. This lets us shift the backround around when we mouse over each element:&lt;/p&gt;
&lt;p&gt;&lt;span style=&#34;color: #808000;&#34;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;$(document).ready(function(){
  $(&#34;div img.bgmove&#34;).pngFix();
    $(&#34;.bgmove&#34;).mousemove(function(e){
    var elWidth = $(e.target).outerWidth();
    var elHeight = $(e.target).outerHeight();
    var bgWidth = 279;
    var bgHeight = 95;
    var x = e.pageX - this.offsetLeft;
    var y = e.pageY - this.offsetTop;
    //var offX = -1 * (x * (bgWidth - elWidth) / elWidth);  // Against the mouse
    var offX = (x * (bgWidth - elWidth) / elWidth) - (bgWidth - elWidth);  // With the mouse
    var offY = -1 * (y * (bgHeight - elHeight) / elHeight); // Against the mouse
    //var offY = (y * (bgHeight - elHeight) / elHeight) - (bgHeight - elHeight);  // With the mouse
    bgPos = offX + &#39;px &#39; + offY + &#39;px&#39;;
    this.style.backgroundPosition = bgPos;
    });
})&lt;/pre&gt;
&lt;p&gt;You can see it all in action &lt;a href=&#34;http://www.zing.org/bgmove.html&#34;&gt;on the demo page&lt;/a&gt;. Combining this with &lt;a href=&#34;http://snook.ca/archives/javascript/jquery-bg-image-animations/&#34;&gt;jQuery animation&lt;/a&gt; is left as an exercise for the reader. The effect works in Firefox, Safari, Chrome, and IE 7+. IE 6 has trouble with the transparent PNG.&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>
