<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>浮山狼de博客 &#187; js</title>
	<atom:link href="https://www.fushanlang.com/tag/js/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fushanlang.com</link>
	<description>next station - 下一站，活在当下，且行且思</description>
	<lastBuildDate>Sat, 29 Nov 2014 15:14:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.2.5</generator>
	<item>
		<title>js图片上传本地预览兼容(IE7-8-9\firefox\chrome)</title>
		<link>https://www.fushanlang.com/js-tu-pian-shang-chuan-ben-di-yu-lan-jian-rong-ie7-8-9firefoxchrome-2256/</link>
		<comments>https://www.fushanlang.com/js-tu-pian-shang-chuan-ben-di-yu-lan-jian-rong-ie7-8-9firefoxchrome-2256/#comments</comments>
		<pubDate>Mon, 17 Dec 2012 08:28:34 +0000</pubDate>
		<dc:creator><![CDATA[fushanlang]]></dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js]]></category>

		<guid isPermaLink="false">http://www.fushanlang.com/blog/?p=2256</guid>
		<description><![CDATA[ #preview{width:300px;height:300px;border:1px solid #000;overflow:hidden;} #imghead {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image);} #preview_size_fake{ /* 该对象只用来在IE下获得图片的原始尺寸，无其它用途 */ filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image); width:300px; visibility:hidden; overflow: hidden; } function previewImage(file) { var MAXWIDTH = 300; var MAXHEIGHT = 300; var div = document.getElementById('preview'); if (file.files &#038;&#038; file.files[0]) { div.innerHTML = ''; var img = document.getElementById('imghead'); img.onload = function(){ var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight); img.width <span style="color:#777"> . . . &#8594; Read More: <a href="https://www.fushanlang.com/js-tu-pian-shang-chuan-ben-di-yu-lan-jian-rong-ie7-8-9firefoxchrome-2256/">js图片上传本地预览兼容(IE7-8-9\firefox\chrome)</a></span>]]></description>
				<content:encoded><![CDATA[<pre name="code" class="html">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <style type="text/css">
        #preview{width:300px;height:300px;border:1px solid #000;overflow:hidden;}
        #imghead {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image);}
        #preview_size_fake{ /* 该对象只用来在IE下获得图片的原始尺寸，无其它用途 */
            filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image);
            width:300px;
            visibility:hidden;
            overflow: hidden;
        }
    </style>
    <script type="text/javascript">
        function previewImage(file)
        {
            var MAXWIDTH  = 300;
            var MAXHEIGHT = 300;
            var div = document.getElementById('preview');
            if (file.files &#038;&#038; file.files[0])
            {
                div.innerHTML = '<img id=imghead>';
                var img = document.getElementById('imghead');
                img.onload = function(){
                    var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
                    img.width = rect.width;
                    img.height = rect.height;
                    img.style.marginLeft = rect.left+'px';
                    img.style.marginTop = rect.top+'px';
                }
                var reader = new FileReader();
                reader.onload = function(evt){img.src = evt.target.result;}
                reader.readAsDataURL(file.files[0]);
            }
            else
            {
                var sFilter='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
                file.select();
                var src = document.selection.createRange().text;
                var objPreviewSizeFake = document.getElementById('preview_size_fake');
                objPreviewSizeFake.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
                div.innerHTML = '<img id=imghead>';

                var img = document.getElementById('imghead');
                img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
                var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, objPreviewSizeFake.offsetWidth, objPreviewSizeFake.offsetHeight);
                status =('rect:'+rect.top+','+rect.left+','+rect.width+','+rect.height);
                div.innerHTML = "<div id=divhead style='width:"+rect.width+"px;height:"+rect.height+"px;margin-top:"+rect.top+"px;margin-left:"+rect.left+"px;"+sFilter+src+"\"'></div>";

            }
        }
        function clacImgZoomParam( maxWidth, maxHeight, width, height ){
            var param = {top:0, left:0, width:width, height:height};
            if( width>maxWidth || height>maxHeight )
            {
                rateWidth = width / maxWidth;
                rateHeight = height / maxHeight;

                if( rateWidth > rateHeight )
                {
                    param.width =  maxWidth;
                    param.height = Math.round(height / rateWidth);
                }else
                {
                    param.width = Math.round(width / rateHeight);
                    param.height = maxHeight;
                }
            }

            param.left = Math.round((maxWidth - param.width) / 2);
            param.top = Math.round((maxHeight - param.height) / 2);
            return param;
        }
    </script>
</head>
<body>
<div id="preview">
    <img id="imghead" border=0 src='' />

</div>
<div style="width:1px;height:1px;overflow: hidden;">
<img id="preview_size_fake" />
</div>
<br/>
<input type="file" onchange="previewImage(this)" />
</body>
</html>  
</pre>
<p>上面由于代码显示控件去除了html header标签，可以参照以下完整的内容:</p>
<p><textarea style="width:100%;height:300px">
<pre>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <style type="text/css">
        #preview{width:300px;height:300px;border:1px solid #000;overflow:hidden;}
        #imghead {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image);}
        #preview_size_fake{ /* 该对象只用来在IE下获得图片的原始尺寸，无其它用途 */
            filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image);
            width:300px;
            visibility:hidden;
            overflow: hidden;
        }
    </style>
    <script type="text/javascript">
        function previewImage(file)
        {
            var MAXWIDTH  = 300;
            var MAXHEIGHT = 300;
            var div = document.getElementById('preview');
            if (file.files &#038;&#038; file.files[0])
            {
                div.innerHTML = '<img id=imghead>';
                var img = document.getElementById('imghead');
                img.onload = function(){
                    var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
                    img.width = rect.width;
                    img.height = rect.height;
                    img.style.marginLeft = rect.left+'px';
                    img.style.marginTop = rect.top+'px';
                }
                var reader = new FileReader();
                reader.onload = function(evt){img.src = evt.target.result;}
                reader.readAsDataURL(file.files[0]);
            }
            else
            {
                var sFilter='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
                file.select();
                var src = document.selection.createRange().text;
                var objPreviewSizeFake = document.getElementById('preview_size_fake');
                objPreviewSizeFake.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
                div.innerHTML = '<img id=imghead>';

                var img = document.getElementById('imghead');
                img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
                var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, objPreviewSizeFake.offsetWidth, objPreviewSizeFake.offsetHeight);
                status =('rect:'+rect.top+','+rect.left+','+rect.width+','+rect.height);
                div.innerHTML = "<div id=divhead style='width:"+rect.width+"px;height:"+rect.height+"px;margin-top:"+rect.top+"px;margin-left:"+rect.left+"px;"+sFilter+src+"\"'></div>";

            }
        }
        function clacImgZoomParam( maxWidth, maxHeight, width, height ){
            var param = {top:0, left:0, width:width, height:height};
            if( width>maxWidth || height>maxHeight )
            {
                rateWidth = width / maxWidth;
                rateHeight = height / maxHeight;

                if( rateWidth > rateHeight )
                {
                    param.width =  maxWidth;
                    param.height = Math.round(height / rateWidth);
                }else
                {
                    param.width = Math.round(width / rateHeight);
                    param.height = maxHeight;
                }
            }

            param.left = Math.round((maxWidth - param.width) / 2);
            param.top = Math.round((maxHeight - param.height) / 2);
            return param;
        }
    </script>
</head>
<body>
<div id="preview">
    <img id="imghead" border=0 src='' />

</div>
<div style="width:1px;height:1px;overflow: hidden;">
<img id="preview_size_fake" />
</div>
<br/>
<input type="file" onchange="previewImage(this)" />
</body>
</html></pre>
<p></textarea></p>
]]></content:encoded>
			<wfw:commentRss>https://www.fushanlang.com/js-tu-pian-shang-chuan-ben-di-yu-lan-jian-rong-ie7-8-9firefoxchrome-2256/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jquery Masonry瀑布流插件(转)</title>
		<link>https://www.fushanlang.com/jquery-masonry-pu-bu-liu-cha-jian-zhuan-2218/</link>
		<comments>https://www.fushanlang.com/jquery-masonry-pu-bu-liu-cha-jian-zhuan-2218/#comments</comments>
		<pubDate>Tue, 07 Aug 2012 04:03:15 +0000</pubDate>
		<dc:creator><![CDATA[fushanlang]]></dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[js]]></category>

		<guid isPermaLink="false">http://www.fushanlang.com/blog/?p=2218</guid>
		<description><![CDATA[<p>如果你经常网上冲浪，这样参差不齐的多栏布局，就象砖块效果砌墙一样，错落有致，是不是很眼熟啊？</p> <p>这种布局适合于小数据块，每个数据块内容相近且没有侧重。通常，随着页面滚动条向下滚动，这种布局还会不断加载数据块并附加至当前尾部。所以，我们给这样的布局起了一个形象的名字 — 瀑布流式布局。</p> <p>Masonry是一款很好用的jquery网页布局插件，它可以去掉不同高度div之间的空白，</p> <p>让你的网页看上去更加的整齐、漂亮！</p> <p>官网插件下载地址以及详解地址：</p> <p>示例demo及文档说明：http://masonry.desandro.com/ （本站离线版下载）</p> <p>你也可以下载打包的html文档在本地查阅：（内含jquery.masonry.min.js 和 jquery.masonry.js 和 实例） Viewing this project locally Via download</p> <p>You can download a zip of all the flat HTML files from http://meta.metafizzy.co/files/masonry-site.zip. 本站下载</p> <p>代码下载地址： https://github.com/desandro/masonry/downloads 本站下载 （里面的demo都有问题，建议还是看上面的官方demo或者本站提供的离线版）</p> <p>以下是官网的实例截图：</p> <p>从这2张图片中就能看到此插件的作用了把！</p> <p>更鲜明的例子，chinaz.com的素材列表页也用了这个jQuery Masonry 插件</p> <p>chinaz.com截图：</p> <p>该如何使用呢，其实很简单，看下代码：</p> test1 test2 test3 test4 </p> <p> // </p> <p>使用说明：</p> <span style="color:#777"> . . . &#8594; Read More: <a href="https://www.fushanlang.com/jquery-masonry-pu-bu-liu-cha-jian-zhuan-2218/">jquery Masonry瀑布流插件(转)</a></span>]]></description>
				<content:encoded><![CDATA[<p>如果你经常网上冲浪，这样参差不齐的多栏布局，就象砖块效果砌墙一样，错落有致，是不是很眼熟啊？</p>
<p>这种布局适合于小数据块，每个数据块内容相近且没有侧重。通常，随着页面滚动条向下滚动，这种布局还会不断加载数据块并附加至当前尾部。所以，我们给这样的布局起了一个形象的名字 — 瀑布流式布局。</p>
<p>Masonry是一款很好用的jquery网页布局插件，它可以去掉不同高度div之间的空白，</p>
<p>让你的网页看上去更加的整齐、漂亮！</p>
<p>官网插件下载地址以及详解地址：</p>
<p>示例demo及文档说明：http://masonry.desandro.com/  （本站离线版下载）</p>
<p>你也可以下载打包的html文档在本地查阅：（内含jquery.masonry.min.js 和 jquery.masonry.js 和 实例）<br />
Viewing this project locally<br />
Via download</p>
<p>You can download a zip of all the flat HTML files from http://meta.metafizzy.co/files/masonry-site.zip.   本站下载</p>
<p>代码下载地址： https://github.com/desandro/masonry/downloads   本站下载 （里面的demo都有问题，建议还是看上面的官方demo或者本站提供的离线版）</p>
<p>以下是官网的实例截图：</p>
<p>从这2张图片中就能看到此插件的作用了把！</p>
<p>更鲜明的例子，chinaz.com的素材列表页也用了这个jQuery Masonry 插件</p>
<p>chinaz.com截图：</p>
<p>该如何使用呢，其实很简单，看下代码：</p>
<div id="”test”">
<div class="”box”">test1</div>
<div class="”box”">test2</div>
<div class="”box”">test3</div>
<div class="”box”">test4 </div>
</p></div>
<p>    <script type="”text/javascript”"> 
    // <![CDATA[  
       $(‘#test’).masonry({  
       singleMode: true,  
       itemSelector: '.box'  
    })  
    // ]]&gt;</script> </p>
<p>使用说明：</p>
<p>配置Masonry相当容易，只需要在jQuery脚本中的wrapping container元素中加上.masonry()方法。</p>
<p>multiple widths:</p>
<p>$(&#8216;#wrapper&#8217;).masonry({ columnWidth: 200 });</p>
<p>same width</p>
<p>$(&#8216;#wrapper&#8217;).masonry({ singleMode: true });</p>
<p>    $(&#8216;#wrapper&#8217;).masonry({  </p>
<p>      singleMode: false,<br />
      // 禁用测量每个浮动元素的宽度。<br />
      // 如果浮动元素具有相同的宽度，设置为true。<br />
      // 默认： false  </p>
<p>      columnWidth: 240,<br />
      // 1列网格的宽度，单位为像素（px）。<br />
      // 默认： 第一个浮动元素外宽度。  </p>
<p>      itemSelector: &#8216;.box:visible&#8217;,<br />
      // 附加选择器，用来指定哪些元素包裹的元素会重新排列。  </p>
<p>      resizeable: true,<br />
      // 绑定一个 Masonry 访问 用来 窗口 resize时布局平滑流动.<br />
      // 默认：true  </p>
<p>      animate: true,<br />
      // 布局重排动画。<br />
      // 默认：false  </p>
<p>      animationOptions: {},<br />
      // 一对动画选项，具体参数可以参考jquery .animate()中的options选项  </p>
<p>      appendedContent: $(&#8216;.new_content&#8217;),<br />
      //  附加选择器元素，用来尾部追加内容。<br />
      // 在集成infinitescroll插件的情况下使用。  </p>
<p>      saveOptions: true,<br />
      // 默认情况下，Masonry 将使用以前Masonry使用过的参数选项,所以你只需要输入一次选项<br />
      // 默认：true  </p>
<p>    },  function() {}<br />
      // 可选择的回调函数<br />
      // &#8216;this&#8217;将指向重排的Masonry适用元素<br />
    );  </p>
<p>BUG：</p>
<p>发现在container窗口的高度计算上，IE与firefox会出现偏差，有可能IE的计算高度比FF的大几十个像素，</p>
<p> 图片瀑布流的简单做法：</p>
<p>这里只说说等宽的图片瀑布流，因为等宽的做出来的效果个人觉得比较好看，</p>
<p>关键是：img的设置，width:100%, 占满整个DIV层，高度height不设置，这样就可以实现了图片能根据宽度等比例缩放，不变形，</p>
<p>而考虑到如果没有这个JS插件失效的情况也能够正常显示，所以给每个box都添加了float:left;浮动和边距</p>
<p>这里的box宽度可以根据container的宽度除以你想一行出现的图片数得到估算值。</p>
<div id="container" style="width:">
<div style="width:200px； float:left；margin:0px 5px">
         <img style="width:100%" />
      </div>
<div style="width:200px； float:left；margin:0px 5px">
         <img style="width:100%" />
      </div>
<div style="width:200px； float:left；margin:0px 5px">
         <img style="width:100%" />
      </div>
<div style="width:200px； float:left；margin:0px 5px">
         <img style="width:100%" />
      </div>
</p></div>
<p>图片高度BUG修正：</p>
<p>      由于网络传输的速度问题，当浏览器加载了dom，但是img图片还没有加载完毕，这个插件在计算图片高度和定位的时候，就会出错，在firefox和chrome中最为明显，尤其是google chrome.<br />
原因：<br />
在chrome浏览器下测试，在图片加载过程中，img的宽度和高度均为0，而在IE下，则浏览器先给img设定了宽度和高度，所以这个插件在IE下使用正常，但在chrome会出错。而这个插件看了官方的image demo也是如此，box层并没有动态生成一个高度值把布局撑开。</p>
<p>解决办法就是先让所有的图片加载完毕，才执行一次masonry()方法。</p>
<p>代码如下：</p>
<p>    <script> 
    var $img=$('.container img');  
    var imgCount=$img.length;  
    $img.load(function(){  
    imgCount--;  
    if(imgCount==0){$('.container').masonry();}  
    });  
    </script> </p>
<p>或者使用它自带的方法imagesLoaded，http://masonry.desandro.com/demos/images.html</p>
<p>    var $container = $(&#8216;#container&#8217;);  </p>
<p>    $container.imagesLoaded( function(){<br />
      $container.masonry({<br />
        itemSelector : &#8216;.box&#8217;<br />
      });<br />
    }); </p>
<p>当然了，这样子的话，在加载图片的时候，你会先看到图片简单的排列而已，没有砖块瀑布流的效果，只有当所有图片加载完成后才会出现砖块效果。所以，至于以上代码加不加，就要考虑你的网站的访问速度了！</p>
]]></content:encoded>
			<wfw:commentRss>https://www.fushanlang.com/jquery-masonry-pu-bu-liu-cha-jian-zhuan-2218/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
