Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1003490
    itshakdeal
    Participant

    Hey, my website is https://yacov.net

    And I’ve add a static image beforme my header

    with this code

    
    
    <?php if(is_front_page()){ ?>
      <img  src="https://yacov.net/wp-content/uploads/2016/04/imagedepresentationtetecligne.gif" class="imageaccueil" >
    <?php }else{ ?>
    <?php x_get_view( 'global', '_slider-above' ); ?>
    <?php } ?>
    
    

    in /yacov.net/wp-content/themes/x/framework/views/ethos

    How can I add this javascript ?

    
    (function() {
    
        var width, height, largeHeader, canvas, ctx, points, target, animateHeader = true;
    
        // Main
        initHeader();
        initAnimation();
        addListeners();
    
        function initHeader() {
            width = window.innerWidth;
            height = window.innerHeight;
            target = {x: width/2, y: height/2};
    
            largeHeader = document.getElementById('large-header');
            largeHeader.style.height = height+'px';
    
            canvas = document.getElementById('demo-canvas');
            canvas.width = width;
            canvas.height = height;
            ctx = canvas.getContext('2d');
    
            // create points
            points = [];
            for(var x = 0; x < width; x = x + width/20) {
                for(var y = 0; y < height; y = y + height/20) {
                    var px = x + Math.random()*width/20;
                    var py = y + Math.random()*height/20;
                    var p = {x: px, originX: px, y: py, originY: py };
                    points.push(p);
                }
            }
    
            // for each point find the 5 closest points
            for(var i = 0; i < points.length; i++) {
                var closest = [];
                var p1 = points[i];
                for(var j = 0; j < points.length; j++) {
                    var p2 = points[j]
                    if(!(p1 == p2)) {
                        var placed = false;
                        for(var k = 0; k < 5; k++) {
                            if(!placed) {
                                if(closest[k] == undefined) {
                                    closest[k] = p2;
                                    placed = true;
                                }
                            }
                        }
    
                        for(var k = 0; k < 5; k++) {
                            if(!placed) {
                                if(getDistance(p1, p2) < getDistance(p1, closest[k])) {
                                    closest[k] = p2;
                                    placed = true;
                                }
                            }
                        }
                    }
                }
                p1.closest = closest;
            }
    
            // assign a circle to each point
            for(var i in points) {
                var c = new Circle(points[i], 2+Math.random()*2, 'rgba(255,255,255,0.3)');
                points[i].circle = c;
            }
        }
    
        // Event handling
        function addListeners() {
            if(!('ontouchstart' in window)) {
                window.addEventListener('mousemove', mouseMove);
            }
            window.addEventListener('scroll', scrollCheck);
            window.addEventListener('resize', resize);
        }
    
        function mouseMove(e) {
            var posx = posy = 0;
            if (e.pageX || e.pageY) {
                posx = e.pageX;
                posy = e.pageY;
            }
            else if (e.clientX || e.clientY)    {
                posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
                posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
            }
            target.x = posx;
            target.y = posy;
        }
    
        function scrollCheck() {
            if(document.body.scrollTop > height) animateHeader = false;
            else animateHeader = true;
        }
    
        function resize() {
            width = window.innerWidth;
            height = window.innerHeight;
            largeHeader.style.height = height+'px';
            canvas.width = width;
            canvas.height = height;
        }
    
        // animation
        function initAnimation() {
            animate();
            for(var i in points) {
                shiftPoint(points[i]);
            }
        }
    
        function animate() {
            if(animateHeader) {
                ctx.clearRect(0,0,width,height);
                for(var i in points) {
                    // detect points in range
                    if(Math.abs(getDistance(target, points[i])) < 4000) {
                        points[i].active = 0.3;
                        points[i].circle.active = 0.6;
                    } else if(Math.abs(getDistance(target, points[i])) < 20000) {
                        points[i].active = 0.1;
                        points[i].circle.active = 0.3;
                    } else if(Math.abs(getDistance(target, points[i])) < 40000) {
                        points[i].active = 0.02;
                        points[i].circle.active = 0.1;
                    } else {
                        points[i].active = 0;
                        points[i].circle.active = 0;
                    }
    
                    drawLines(points[i]);
                    points[i].circle.draw();
                }
            }
            requestAnimationFrame(animate);
        }
    
        function shiftPoint(p) {
            TweenLite.to(p, 1+1*Math.random(), {x:p.originX-50+Math.random()*100,
                y: p.originY-50+Math.random()*100, ease:Circ.easeInOut,
                onComplete: function() {
                    shiftPoint(p);
                }});
        }
    
        // Canvas manipulation
        function drawLines(p) {
            if(!p.active) return;
            for(var i in p.closest) {
                ctx.beginPath();
                ctx.moveTo(p.x, p.y);
                ctx.lineTo(p.closest[i].x, p.closest[i].y);
                ctx.strokeStyle = 'rgba(156,217,249,'+ p.active+')';
                ctx.stroke();
            }
        }
    
        function Circle(pos,rad,color) {
            var _this = this;
    
            // constructor
            (function() {
                _this.pos = pos || null;
                _this.radius = rad || null;
                _this.color = color || null;
            })();
    
            this.draw = function() {
                if(!_this.active) return;
                ctx.beginPath();
                ctx.arc(_this.pos.x, _this.pos.y, _this.radius, 0, 2 * Math.PI, false);
                ctx.fillStyle = 'rgba(156,217,249,'+ _this.active+')';
                ctx.fill();
            };
        }
    
        // Util
        function getDistance(p1, p2) {
            return Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2);
        }
        
    })();
    
    

    I want my image be like this : http://tympanus.net/Development/AnimatedHeaderBackgrounds/

    #1003602
    Christopher
    Moderator

    Hi there,

    Please update your code to:

    <?php if(is_front_page()){ ?>
     <?php echo do_shortcode("[x_section bg_image='https://yacov.net/wp-content/uploads/2016/04/imagedepresentationtetecligne.gif'][x_raw_content]
     	<script>
     	(function() {
    
        var width, height, largeHeader, canvas, ctx, points, target, animateHeader = true;
    
        // Main
        initHeader();
        initAnimation();
        addListeners();
    
        function initHeader() {
            width = window.innerWidth;
            height = window.innerHeight;
            target = {x: width/2, y: height/2};
    
            largeHeader = document.getElementById('large-header');
            largeHeader.style.height = height+'px';
    
            canvas = document.getElementById('demo-canvas');
            canvas.width = width;
            canvas.height = height;
            ctx = canvas.getContext('2d');
    
            // create points
            points = [];
            for(var x = 0; x < width; x = x + width/20) {
                for(var y = 0; y < height; y = y + height/20) {
                    var px = x + Math.random()*width/20;
                    var py = y + Math.random()*height/20;
                    var p = {x: px, originX: px, y: py, originY: py };
                    points.push(p);
                }
            }
    
            // for each point find the 5 closest points
            for(var i = 0; i < points.length; i++) {
                var closest = [];
                var p1 = points[i];
                for(var j = 0; j < points.length; j++) {
                    var p2 = points[j]
                    if(!(p1 == p2)) {
                        var placed = false;
                        for(var k = 0; k < 5; k++) {
                            if(!placed) {
                                if(closest[k] == undefined) {
                                    closest[k] = p2;
                                    placed = true;
                                }
                            }
                        }
    
                        for(var k = 0; k < 5; k++) {
                            if(!placed) {
                                if(getDistance(p1, p2) < getDistance(p1, closest[k])) {
                                    closest[k] = p2;
                                    placed = true;
                                }
                            }
                        }
                    }
                }
                p1.closest = closest;
            }
    
            // assign a circle to each point
            for(var i in points) {
                var c = new Circle(points[i], 2+Math.random()*2, 'rgba(255,255,255,0.3)');
                points[i].circle = c;
            }
        }
    
        // Event handling
        function addListeners() {
            if(!('ontouchstart' in window)) {
                window.addEventListener('mousemove', mouseMove);
            }
            window.addEventListener('scroll', scrollCheck);
            window.addEventListener('resize', resize);
        }
    
        function mouseMove(e) {
            var posx = posy = 0;
            if (e.pageX || e.pageY) {
                posx = e.pageX;
                posy = e.pageY;
            }
            else if (e.clientX || e.clientY)    {
                posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
                posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
            }
            target.x = posx;
            target.y = posy;
        }
    
        function scrollCheck() {
            if(document.body.scrollTop > height) animateHeader = false;
            else animateHeader = true;
        }
    
        function resize() {
            width = window.innerWidth;
            height = window.innerHeight;
            largeHeader.style.height = height+'px';
            canvas.width = width;
            canvas.height = height;
        }
    
        // animation
        function initAnimation() {
            animate();
            for(var i in points) {
                shiftPoint(points[i]);
            }
        }
    
        function animate() {
            if(animateHeader) {
                ctx.clearRect(0,0,width,height);
                for(var i in points) {
                    // detect points in range
                    if(Math.abs(getDistance(target, points[i])) < 4000) {
                        points[i].active = 0.3;
                        points[i].circle.active = 0.6;
                    } else if(Math.abs(getDistance(target, points[i])) < 20000) {
                        points[i].active = 0.1;
                        points[i].circle.active = 0.3;
                    } else if(Math.abs(getDistance(target, points[i])) < 40000) {
                        points[i].active = 0.02;
                        points[i].circle.active = 0.1;
                    } else {
                        points[i].active = 0;
                        points[i].circle.active = 0;
                    }
    
                    drawLines(points[i]);
                    points[i].circle.draw();
                }
            }
            requestAnimationFrame(animate);
        }
    
        function shiftPoint(p) {
            TweenLite.to(p, 1+1*Math.random(), {x:p.originX-50+Math.random()*100,
                y: p.originY-50+Math.random()*100, ease:Circ.easeInOut,
                onComplete: function() {
                    shiftPoint(p);
                }});
        }
    
        // Canvas manipulation
        function drawLines(p) {
            if(!p.active) return;
            for(var i in p.closest) {
                ctx.beginPath();
                ctx.moveTo(p.x, p.y);
                ctx.lineTo(p.closest[i].x, p.closest[i].y);
                ctx.strokeStyle = 'rgba(156,217,249,'+ p.active+')';
                ctx.stroke();
            }
        }
    
        function Circle(pos,rad,color) {
            var _this = this;
    
            // constructor
            (function() {
                _this.pos = pos || null;
                _this.radius = rad || null;
                _this.color = color || null;
            })();
    
            this.draw = function() {
                if(!_this.active) return;
                ctx.beginPath();
                ctx.arc(_this.pos.x, _this.pos.y, _this.radius, 0, 2 * Math.PI, false);
                ctx.fillStyle = 'rgba(156,217,249,'+ _this.active+')';
                ctx.fill();
            };
        }
    
        // Util
        function getDistance(p1, p2) {
            return Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2);
        }
        
    })();</script>[/x_raw_content][/x_section]"); ?>

    Hope it helps.

    #1004067
    itshakdeal
    Participant
    This reply has been marked as private.
    #1004369
    Rue Nel
    Moderator

    Hello There,

    I have made some changes to the file. However those changes are not taking effect. Since you are using CloudFlare and you have installed a caching plugin like W3 Total Cache, please keep in mind that after doing every updates and changes, always remember to clear all caches when updating so that the code from the latest release is always in use. This will help you to avoid any potential errors. It is best that you temporarily disable CloudFlare and your caching plugin to see the changes immediately. They are best to turn on only when you’ve finished building the site.

    Please let us know how it goes.

    #1004464
    itshakdeal
    Participant

    I’ve clean the cache and disable those service, but my image have dissapear

    #1004559
    Rue Nel
    Moderator

    Hello There,

    I edited your wp-header.php again and use this code:

    <?php
    
    // =============================================================================
    // VIEWS/ETHOS/WP-HEADER.PHP
    // -----------------------------------------------------------------------------
    // Header output for Ethos.
    // =============================================================================
    
    ?>
    
    <?php x_get_view( 'global', '_header' ); ?>
    
    <?php if( is_front_page() ){ ?>
       <?php echo do_shortcode("[cs_section id='large-header' class='large-header' bg_image='https://yacov.net/wp-content/uploads/2016/04/imagedepresentationtetecligne.gif'][cs_raw_content]
        <canvas id='demo-canvas' width='100%' height='100%'></canvas>
        <script>
        (function() {
    
          var width, height, largeHeader, canvas, ctx, points, target, animateHeader = true;
    
          // Main
          initHeader();
          initAnimation();
          addListeners();
    
          function initHeader() {
              width = window.innerWidth;
              height = window.innerHeight;
              target = {x: width/2, y: height/2};
    
              largeHeader = document.getElementById('large-header');
              largeHeader.style.height = height+'px';
    
              canvas = document.getElementById('demo-canvas');
              canvas.width = width;
              canvas.height = height;
              ctx = canvas.getContext('2d');
    
              // create points
              points = [];
              for(var x = 0; x < width; x = x + width/20) {
                  for(var y = 0; y < height; y = y + height/20) {
                      var px = x + Math.random()*width/20;
                      var py = y + Math.random()*height/20;
                      var p = {x: px, originX: px, y: py, originY: py };
                      points.push(p);
                  }
              }
    
              // for each point find the 5 closest points
              for(var i = 0; i < points.length; i++) {
                  var closest = [];
                  var p1 = points[i];
                  for(var j = 0; j < points.length; j++) {
                      var p2 = points[j]
                      if(!(p1 == p2)) {
                          var placed = false;
                          for(var k = 0; k < 5; k++) {
                              if(!placed) {
                                  if(closest[k] == undefined) {
                                      closest[k] = p2;
                                      placed = true;
                                  }
                              }
                          }
    
                          for(var k = 0; k < 5; k++) {
                              if(!placed) {
                                  if(getDistance(p1, p2) < getDistance(p1, closest[k])) {
                                      closest[k] = p2;
                                      placed = true;
                                  }
                              }
                          }
                      }
                  }
                  p1.closest = closest;
              }
    
              // assign a circle to each point
              for(var i in points) {
                  var c = new Circle(points[i], 2+Math.random()*2, 'rgba(255,255,255,0.3)');
                  points[i].circle = c;
              }
          }
    
          // Event handling
          function addListeners() {
              if(!('ontouchstart' in window)) {
                  window.addEventListener('mousemove', mouseMove);
              }
              window.addEventListener('scroll', scrollCheck);
              window.addEventListener('resize', resize);
          }
    
          function mouseMove(e) {
              var posx = posy = 0;
              if (e.pageX || e.pageY) {
                  posx = e.pageX;
                  posy = e.pageY;
              }
              else if (e.clientX || e.clientY)    {
                  posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
                  posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
              }
              target.x = posx;
              target.y = posy;
          }
    
          function scrollCheck() {
              if(document.body.scrollTop > height) animateHeader = false;
              else animateHeader = true;
          }
    
          function resize() {
              width = window.innerWidth;
              height = window.innerHeight;
              largeHeader.style.height = height+'px';
              canvas.width = width;
              canvas.height = height;
          }
    
          // animation
          function initAnimation() {
              animate();
              for(var i in points) {
                  shiftPoint(points[i]);
              }
          }
    
          function animate() {
              if(animateHeader) {
                  ctx.clearRect(0,0,width,height);
                  for(var i in points) {
                      // detect points in range
                      if(Math.abs(getDistance(target, points[i])) < 4000) {
                          points[i].active = 0.3;
                          points[i].circle.active = 0.6;
                      } else if(Math.abs(getDistance(target, points[i])) < 20000) {
                          points[i].active = 0.1;
                          points[i].circle.active = 0.3;
                      } else if(Math.abs(getDistance(target, points[i])) < 40000) {
                          points[i].active = 0.02;
                          points[i].circle.active = 0.1;
                      } else {
                          points[i].active = 0;
                          points[i].circle.active = 0;
                      }
    
                      drawLines(points[i]);
                      points[i].circle.draw();
                  }
              }
              requestAnimationFrame(animate);
          }
    
          function shiftPoint(p) {
              TweenLite.to(p, 1+1*Math.random(), {x:p.originX-50+Math.random()*100,
                  y: p.originY-50+Math.random()*100, ease:Circ.easeInOut,
                  onComplete: function() {
                      shiftPoint(p);
                  }});
          }
    
          // Canvas manipulation
          function drawLines(p) {
              if(!p.active) return;
              for(var i in p.closest) {
                  ctx.beginPath();
                  ctx.moveTo(p.x, p.y);
                  ctx.lineTo(p.closest[i].x, p.closest[i].y);
                  ctx.strokeStyle = 'rgba(156,217,249,'+ p.active+')';
                  ctx.stroke();
              }
          }
    
          function Circle(pos,rad,color) {
              var _this = this;
    
              // constructor
              (function() {
                  _this.pos = pos || null;
                  _this.radius = rad || null;
                  _this.color = color || null;
              })();
    
              this.draw = function() {
                  if(!_this.active) return;
                  ctx.beginPath();
                  ctx.arc(_this.pos.x, _this.pos.y, _this.radius, 0, 2 * Math.PI, false);
                  ctx.fillStyle = 'rgba(156,217,249,'+ _this.active+')';
                  ctx.fill();
              };
          }
    
          // Util
          function getDistance(p1, p2) {
              return Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2);
          }
          
      })();</script>[/cs_raw_content][/cs_section]"); ?>
    
            
    <?php }else{ ?>
    <?php x_get_view( 'global', '_slider-above' ); ?>
    <?php } ?>
    
      <header class="<?php x_masthead_class(); ?> this is it" role="banner">
        <?php x_get_view( 'ethos', '_post', 'carousel' ); ?>
        <?php x_get_view( 'global', '_topbar' ); ?>
        <?php x_get_view( 'global', '_navbar' ); ?>
        <?php x_get_view( 'ethos', '_breadcrumbs' ); ?>
      </header>
    
      <?php x_get_view( 'global', '_slider-below' ); ?>
      <?php x_get_view( 'ethos', '_landmark-header' ); ?>

    It seems all my changes doesn’t get reflected in your site. Am I accessing the files in the correct directory?

    #1020380
    itshakdeal
    Participant

    I’ve try to add you’re code but it already doesn’t work yet.
    (You have to add it in /yacov.net/wp-content/themes/x/framework/views/ethos because I have not activate the child theme)

    #1021146
    Nico
    Moderator

    Hi There,

    Would you mind setting up a child theme so that we could not damage the main core or theme and to prevent any auto changes in case there is an update. To set up child theme,

    https://community.theme.co/kb/how-to-setup-child-themes/

    Hope it helps.

    Let us know how it goes.

    Thanks.

  • <script> jQuery(function($){ $("#no-reply-1003490 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>