Difference between revisions of "Template:NKU China/js/share"

(Created page with " var debug = true; var igem = document.location.href.includes('https://2016.igem.org/'); //element is $(<img>), which is 100% embed in its parent. So aut...")
 
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
        var debug = true;
+
var rem = Number($('html').css('font-size').replace('px', ''));
        var igem = document.location.href.includes('https://2016.igem.org/');
+
        function log(value) { console.log(value); }
        //element is $(<img>), which is 100% embed in its parent. So automatically adjust the parent can simultaneously automatically adjust the <img>
+
        function particles() { $('#particles-js').toggle(); }
        var auto_adjust_parent = function (element) {
+
        function adjust_figure(scale) {
            var impl = function () {
+
             $('figure').each(
                var parent = $(element).parent();
+
                function (index, value) {
                parent.width(parent.parent().width());
+
                    var max_width = $(value).find('span').width() / rem * scale + 'rem';
                parent.height(parent.parent().width() * 9 / 16);
+
                     $(value).css('max-width', max_width);
            }
+
                 }
 
+
             )
            impl();
+
             window.addEventListener('resize', impl)
+
        }
+
        //img is $(<img>), local is local path, igem is igem server's path
+
        var load_img = function (img, local, server) {
+
            img.each(function (index, value) {
+
                var image = new Image();
+
                image.onload = function () { $(value).attr('src', image.src); };
+
                if (igem)
+
                    image.src = server;
+
                else
+
                     image.src = local;
+
            })
+
        }
+
        //the parameters are all jqueries
+
        var switcher = function (tabs, contents_array, tab) {
+
            var index = tabs.index(tab);
+
            contents_array.forEach(function (value) {
+
                value.hide();
+
                 value.slice(index, index + 1).show();
+
             });
+
 
         }
 
         }

Latest revision as of 16:16, 19 October 2016

var rem = Number($('html').css('font-size').replace('px', ));

       function log(value) { console.log(value); }
       function particles() { $('#particles-js').toggle(); }
       function adjust_figure(scale) {
           $('figure').each(
               function (index, value) {
                   var max_width = $(value).find('span').width() / rem * scale + 'rem';
                   $(value).css('max-width', max_width);
               }
           )
       }