Changeset 3334980
- Timestamp:
- 07/27/2025 07:32:30 PM (8 months ago)
- Location:
- cb-parallax/tags/0.9.9
- Files:
-
- 5 edited
-
.idea/workspace.xml (modified) (4 diffs)
-
public/class-public.php (modified) (3 diffs)
-
public/css/public.css (modified) (2 diffs)
-
public/js/public.js (modified) (30 diffs)
-
vendor/smoothscroll/smoothscroll.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
cb-parallax/tags/0.9.9/.idea/workspace.xml
r3330924 r3334980 7 7 <list default="true" id="4d0afb40-0a8b-4c9b-aa05-50b615bbef77" name="Changes" comment=""> 8 8 <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> 9 <change beforePath="$PROJECT_DIR$/public/css/public.css" beforeDir="false" afterPath="$PROJECT_DIR$/public/css/public.css" afterDir="false" /> 10 <change beforePath="$PROJECT_DIR$/public/js/public.js" beforeDir="false" afterPath="$PROJECT_DIR$/public/js/public.js" afterDir="false" /> 11 <change beforePath="$PROJECT_DIR$/vendor/smoothscroll/smoothscroll.js" beforeDir="false" afterPath="$PROJECT_DIR$/vendor/smoothscroll/smoothscroll.js" afterDir="false" /> 9 12 </list> 10 13 <option name="SHOW_DIALOG" value="false" /> … … 25 28 <option name="showLibraryContents" value="true" /> 26 29 </component> 27 <component name="PropertiesComponent">{ 28 "keyToString": { 29 "ModuleVcsDetector.initialDetectionPerformed": "true", 30 "RunOnceActivity.ShowReadmeOnStart": "true", 31 "node.js.detected.package.eslint": "true", 32 "node.js.detected.package.tslint": "true", 33 "node.js.selected.package.eslint": "(autodetect)", 34 "node.js.selected.package.tslint": "(autodetect)", 35 "nodejs_package_manager_path": "npm", 36 "vue.rearranger.settings.migration": "true" 30 <component name="PropertiesComponent"><![CDATA[{ 31 "keyToString": { 32 "ModuleVcsDetector.initialDetectionPerformed": "true", 33 "Node.js.public.js.executor": "Debug", 34 "RunOnceActivity.ShowReadmeOnStart": "true", 35 "node.js.detected.package.eslint": "true", 36 "node.js.detected.package.tslint": "true", 37 "node.js.selected.package.eslint": "(autodetect)", 38 "node.js.selected.package.tslint": "(autodetect)", 39 "nodejs_package_manager_path": "npm", 40 "vue.rearranger.settings.migration": "true" 37 41 } 38 }</component> 42 }]]></component> 43 <component name="RunManager"> 44 <configuration name="public.js" type="NodeJSConfigurationType" nameIsGenerated="true" path-to-js-file="public.js" typescript-loader="bundled" working-dir="$PROJECT_DIR$/public/js"> 45 <method v="2" /> 46 </configuration> 47 </component> 39 48 <component name="SharedIndexes"> 40 49 <attachedChunks> … … 85 94 <workItem from="1752973638946" duration="7000" /> 86 95 <workItem from="1753016362411" duration="16000" /> 96 <workItem from="1753119818017" duration="313000" /> 97 <workItem from="1753120455167" duration="598000" /> 98 <workItem from="1753122306490" duration="597000" /> 99 <workItem from="1753127905242" duration="575000" /> 100 <workItem from="1753200574308" duration="596000" /> 101 <workItem from="1753221778368" duration="865000" /> 87 102 </task> 88 103 <servers /> … … 91 106 <option name="version" value="3" /> 92 107 </component> 108 <component name="XDebuggerManager"> 109 <breakpoint-manager> 110 <breakpoints> 111 <line-breakpoint enabled="true" type="javascript"> 112 <url>file://$PROJECT_DIR$/public/js/public.js</url> 113 <line>275</line> 114 <properties lambdaOrdinal="-1" /> 115 <option name="timeStamp" value="1" /> 116 </line-breakpoint> 117 </breakpoints> 118 </breakpoint-manager> 119 </component> 93 120 </project> -
cb-parallax/tags/0.9.9/public/class-public.php
r3330924 r3334980 108 108 'enqueue_styles' 109 109 ], 14); 110 //add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts'], 14);111 110 add_action('wp_enqueue_scripts', [ 112 111 $this, … … 129 128 wp_enqueue_style('cb-parallax-public-css', CBPARALLAX_ROOT_URL.'public/css/public.css', [], $this->version); 130 129 } 131 132 /** 133 * Registers the javascript files with WordPress. 134 * 135 * @return void 136 * @since 0.9.0 137 */ 138 public function enqueue_scripts() : void 139 { 140 /** 141 * @var \WP_Post $post 142 */ global $post; 143 144 // If there is no image at all, we stop here 145 /*if (false === (new MenuIncludes\cb_parallax_options($this->domain))->determine_image_source()) { 146 return; 147 }*/ 148 149 /** 150 * If the image was not found, we bail early. 151 */ 152 if (true !== $this->options->is_image_in_media_library($post)) { 153 return; 154 } 155 156 wp_enqueue_script('jquery'); 157 158 //$this->set_plugin_options($post); 159 160 wp_enqueue_script('cb-parallax-inc-raf-js', CBPARALLAX_ROOT_URL.'vendor/raf/raf.js', ['jquery'], $this->version, true); 161 162 wp_enqueue_script('cb-parallax-inc-smoothscroll-js', CBPARALLAX_ROOT_URL.'vendor/smoothscroll/smoothscroll.js', ['jquery'], $this->version, true); 163 164 // Parallax script 165 wp_enqueue_script('cb-parallax-public-js', CBPARALLAX_ROOT_URL.'public/js/public.js', [ 166 'jquery', 167 'cb-parallax-inc-raf-js', 168 'cb-parallax-inc-smoothscroll-js' 169 ], $this->version, true); 170 171 // Layout script 172 $options = get_option('cb_parallax_options'); 173 if ('1' === $options['cb_parallax_boxed_layout']) { 174 wp_enqueue_script('cb-parallax-layout-js', CBPARALLAX_ROOT_URL.'public/js/layout.js', ['jquery'], $this->version, true); 175 } 176 } 130 177 131 /** 178 132 * @return void … … 239 193 'cb-parallax-inc-raf-js', 240 194 'cb-parallax-inc-smoothscroll-js' 241 ], $this->version, true);195 ], /*$this->version*/ time(), true); 242 196 } 243 197 } -
cb-parallax/tags/0.9.9/public/css/public.css
r3330924 r3334980 18 18 background: repeat; 19 19 background-color: transparent; 20 overflow: visible; 20 21 } 21 22 … … 24 25 position: fixed; 25 26 background: no-repeat fixed; 26 overflow: hidden;27 overflow: visible; 27 28 z-index: -2 28 29 } -
cb-parallax/tags/0.9.9/public/js/public.js
r3330924 r3334980 1 1 /*jshint esversion: 6 */ 2 3 // Main Script 2 4 (function($) { 3 5 "use strict"; 4 6 5 //let cbPublicIsMobile = true === /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? '1' : '0';6 7 let $instance = null; 7 8 let viewport = $(window); 9 10 //let $document = $('document'); 8 11 9 12 function CbParallaxPublic() … … 36 39 uses_assumed_background_color: '0' 37 40 }; 41 this.effect = this.cbParallaxPublic.image_options.effect_type; 38 42 this.direction = undefined !== this.cbParallaxPublic.image_options.direction ? this.cbParallaxPublic.image_options.direction : this.defaultOptions.direction; 43 this.direction = 'Parallax' !== this.effect ? 'vertical' : this.direction; 44 39 45 this.verticalScrollDirection = undefined !== this.cbParallaxPublic.image_options.vertical_scroll_direction ? this.cbParallaxPublic.image_options.vertical_scroll_direction : this.defaultOptions.vertical_scroll_direction; 40 46 this.horizontalScrollDirection = undefined !== this.cbParallaxPublic.image_options.horizontal_scroll_direction ? this.cbParallaxPublic.image_options.horizontal_scroll_direction : this.defaultOptions.horizontal_scroll_direction; … … 44 50 this.parallaxEnabled = undefined !== this.cbParallaxPublic.plugin_options.parallax_enabled ? this.cbParallaxPublic.plugin_options.parallax_enabled : '0'; 45 51 this.allowOverride = undefined !== this.cbParallaxPublic.plugin_options.allow_override ? this.cbParallaxPublic.plugin_options.allow_override : '0'; 46 //this.disableOnMobile = undefined !== this.cbParallaxPublic.plugin_options.disable_on_mobile ? this.cbParallaxPublic.plugin_options.disable_on_mobile : '0';47 52 // 48 53 this.canParallax = undefined !== this.cbParallaxPublic.image_options.can_parallax ? this.cbParallaxPublic.image_options.can_parallax : '0'; … … 65 70 color: undefined !== this.cbParallaxPublic.overlay_options.overlay_color ? this.cbParallaxPublic.overlay_options.overlay_color : this.defaultOptions.overlay_color 66 71 }; 67 68 this.imageAspectRatio = this.getBackgroundImageAspectRatio(); 72 //this.canvasDim = []; 73 /*this.canvasDim.x = this.getCanvasDimensions()[x]; 74 this.canvasDim.y = this.getCanvasDimensions()[y];*/ 69 75 this.context = null; 70 76 this.img = null; 71 this.parallaxfactor = '1.2'; 77 this.scaleFactor = undefined !== this.cbParallaxPublic.scale_factor ? this.cbParallaxPublic.scale_factor : 1.5; 78 this.imageAspectRatio = null/* = this.getBackgroundImageAspectRatio()*/; 79 this.scrollFactor = parseFloat('1.2'); 80 this.viewport = []; 81 this.viewport.x = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0); 82 this.viewport.y = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0); 72 83 $instance = this; 73 84 } … … 77 88 /// Events 78 89 addEvents: function() { 79 let viewport = $(window); 80 if ('1' === this.canParallax && '1' === this.parallaxEnabled) { 81 viewport.on('scroll', {context: this}, this.parallaxOnScroll); 82 viewport.on('resize', {context: this}, this.parallaxOnResize); 83 } else { 84 viewport.on('resize', {context: this}, this.staticBackgroundImageOnResize); 85 } 86 }, 90 //let viewport = $(window); 91 if ('1' === $instance.canParallax && '1' === $instance.parallaxEnabled) { 92 viewport.on('scroll', {context: this}, $instance.parallaxOnScroll); 93 //viewport.on('scroll', {context: this}, $instance.actionOnScroll); 94 viewport.on('resize', {context: this}, $instance.parallaxOnResize); 95 } 96 }, 97 98 actionOnScroll: function(event) { 99 let $this = $instance; 100 if (undefined !== event) { 101 $this = event.data.context; 102 } 103 104 const scrollY = window.scrollY; 105 const el = document.getElementById('cb_parallax_canvas'); 106 //const effect = 'Parallax'; 107 //const effect = 'Spiral Scroll'; 108 switch ($instance.effect) { 109 case 'Parallax': 110 $this.parallaxOnScroll(event); 111 break; 112 case 'Spiral Scroll': 113 //let a = $this.get2dTransformRatios(spiralScroll, el, scrollY); 114 $this.spiralScroll(el, scrollY); 115 break; 116 case 'Sine Wave': 117 $this.sineWaveFloat(el, scrollY); 118 break; 119 case 'Golden Ratio': 120 $this.goldenRatioScale(el, scrollY); 121 break; 122 case 'Fibonacci': 123 $this.fibonacciPath(el, scrollY); 124 break; 125 case 'Radial Outward': 126 $this.radialOutwardMovement(el, scrollY); 127 break; 128 case 'orbital': 129 $this.orbitalLayers(el, scrollY); 130 break; 131 case 'tornado': 132 $this.tornadoTwirl(el, scrollY); 133 break; 134 case 'diagonal': 135 $this.diagonalParallax(el, scrollY); 136 break; 137 case 'ocean-wave': 138 $this.oceanWaveLayers(el, scrollY); 139 break; 140 case 'vortex': 141 $this.vortexInOut(el, scrollY); 142 break; 143 case 'perspective-flip': 144 $this.perspectiveFlip(el, scrollY); 145 break; 146 case 'random-drift': 147 $this.randomDrift(el, scrollY); 148 break; 149 case 'depth-fog': 150 $this.depthFog(el, scrollY); 151 break; 152 case 'parallax-stars': 153 $this.parallaxStars(el, scrollY); 154 break; 155 case 'logarithmic-spiral': 156 $this.logarithmicSpiral(el, scrollY); 157 break; 158 case 'grid-morph': 159 $this.gridMorph(el, scrollY); 160 break; 161 case 'path-follow': 162 $this.pathFollowing(el, scrollY); 163 break; 164 case 'magnetic': 165 $this.magneticEasing(el, scrollY); 166 break; 167 case 'infinite-loop': 168 $this.infiniteLoop(el, scrollY); 169 break; 170 } 171 }, 172 173 /*get2dTransformRatios: function(fn, el, scrollY) { 174 let imageWidth = this.image.width; 175 let imageHeight = this.image.height; 176 let scrollratio = this.getScrollRatio(); 177 let a = fn(el, scrollY); 178 let b = 2; 179 return a; 180 },*/ 87 181 88 182 /// Init 89 183 init: function() { 90 if ('none' !== this.image.src && '1' === this.canParallax /*&& '0' === this.disableOnMobile*/) {91 this.imports = {184 if ('none' !== $instance.image.src && '1' === $instance.canParallax) { 185 $instance.imports = { 92 186 requestAnimationFrame: requestAnimationFrame 93 187 }; 94 188 window.__forceSmoothScrollPolyfill__ = true; 95 this.addEvents(); 189 190 //$instance.scrollFactor = $instance.getScrollRatio(); 191 $instance.imageAspectRatio = $instance.getBackgroundImageAspectRatio(); 192 193 $instance.addEvents(); 96 194 } 97 195 }, 98 196 99 197 initBackground: function() { 100 if ('none' !== this.image.src) { 101 if ('parallax' === this.getBackgroundMode()) { 102 this.initParallaxBackground(); 103 } else { 104 this.initStaticBackground(); 105 } 106 } 107 }, 108 109 initParallaxBackground: function() { 198 if ('none' !== $instance.image.src) { 199 //$instance.doBackground(); 200 $('html').attr('class', 'cbpHtml'); 201 $('body').attr('class', 'cbpBody'); 202 $instance.setupCanvas(); 203 $instance.setupOverlay(); 204 $instance.addCss(); 205 206 let imageDim = $instance.getImageDimensions(); 207 //this.canvasDim = this.getCanvasDimensions(); 208 let canvasDim = $instance.getCanvasDimensions(); 209 let canvas = document.getElementById('cb_parallax_canvas'); 210 let context = canvas.getContext('2d'); 211 $instance.img = new Image(); 212 let sx = 0; 213 let sy = 0; 214 let sWidth = imageDim.width; 215 let sHeight = imageDim.height; 216 let dx = -((imageDim.width - viewport.width()) / 2).toFixed(0); 217 let dy = 0; 218 let dWidth = viewport.innerWidth()/*imageDim.width*/; 219 let dHeight = viewport.innerHeight()/*Math.abs((parseInt(imageDim.height) + parseInt(imageDim.height / $instance.scrollFactor)))*/; 220 221 $instance.img.onload = function() { 222 let image = this; 223 context.drawImage(this, 0, 0, canvasDim.x, canvasDim.y); 224 225 //context.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight); 226 //context.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight); 227 //context.drawImage(this, dx, dy, dWidth, dHeight); 228 //context.drawImage(image, 0, 0); 229 /*context.drawImage( 230 this, 231 /!*(-imageDim.width * 1).toFixed(0)*!/0, 232 /!*(-imageDim.height * 1).toFixed(0)*!/0, 233 (imageDim.width * 2).toFixed(0), 234 (imageDim.height * 2).toFixed(0), 235 0, 236 0, 237 (canvasDim.x * 2).toFixed(0), 238 (canvasDim.y * 2).toFixed(0) 239 );*/ 240 $instance.doParallaxBackgroundImageMovement(); 241 //$instance.parallaxOnResize(); 242 }; 243 $instance.img.src = $instance.image.src + '?' + encodeURIComponent(new Date().toDateString()); 244 } 245 }, 246 247 /*doBackground: function() { 110 248 $('html').attr('class', 'cbpHtml'); 111 249 $('body').attr('class', 'cbpBody'); 112 this.setupCanvas(); 113 this.setupOverlay(); 114 this.addCss(); 115 let imageDim = this.getImageDimensions(); 250 $instance.setupCanvas(); 251 $instance.setupOverlay(); 252 $instance.addCss(); 253 let imageDim = $instance.getImageDimensions(); 254 //this.canvasDim = this.getCanvasDimensions(); 255 let canvasDim = $instance.getCanvasDimensions(); 116 256 let canvas = document.getElementById('cb_parallax_canvas'); 117 257 let context = canvas.getContext('2d'); 118 this.img = new Image();119 let $this = this;120 121 this.img.onload = function() {258 $instance.img = new Image(); 259 //let $this = this; 260 261 $instance.img.onload = function() { 122 262 context.drawImage(this, 0, 0, imageDim.width, imageDim.height); 123 $this.doParallaxBackgroundImage(); 263 /!*context.drawImage( 264 this, 265 /!*(-imageDim.width * 1).toFixed(0)*!/0, 266 /!*(-imageDim.height * 1).toFixed(0)*!/0, 267 (imageDim.width * 2).toFixed(0), 268 (imageDim.height * 2).toFixed(0), 269 0, 270 0, 271 (canvasDim.x * 2).toFixed(0), 272 (canvasDim.y * 2).toFixed(0) 273 );*!/ 274 $instance.doParallaxBackgroundImageMovement(); 275 $instance.parallaxOnResize(); 124 276 }; 125 this.img.src = this.image.src + '?' + encodeURIComponent(new Date().toDateString()); 126 }, 127 128 initStaticBackground: function() { 129 this.setupOverlay(); 130 this.addCss(); 131 this.setupStaticBackgroundImageContainer(); 132 }, 277 $instance.img.src = $instance.image.src + '?' + encodeURIComponent(new Date().toDateString()); 278 },*/ 133 279 134 280 setupCanvas: function() { 135 281 if (0 === $('#cb_parallax_canvas').length) { 136 const canvasDim = this.getCanvasDimensions(); 137 const text = '<div id="cb_parallax_overlay"></div><canvas id="cb_parallax_canvas" class="custom-background" width="' + canvasDim.x + '" height="' + canvasDim.y + '" style="background-color: ' + this.image.backgroundColor + '"></canvas>'; 282 let canvasDim = $instance.getCanvasDimensions(); 283 const text = '<div id="cb_parallax_overlay"></div><canvas id="cb_parallax_canvas" class="custom-background" width="' + canvasDim.x + '" height="' + canvasDim.y + '" style="background-color: ' + $instance.image.backgroundColor + '"></canvas>'; 284 //const text = '<div id="cb_parallax_overlay"></div><canvas id="cb_parallax_canvas" class="custom-background"></canvas>'; 138 285 $(text).insertBefore('.cbpHtml > head'); 139 286 } … … 142 289 setupOverlay: function() { 143 290 if (0 === $('#cb_parallax_overlay').length) { 144 this.overlayContainer = $('#cb_parallax_overlay');145 let overlayBackgroundColor = this.cbParallaxPublic.image_options.overlay_color;146 let overlayOpacity = this.extractOpacity(this.cbParallaxPublic.image_options.overlay_opacity);147 148 this.overlayContainer.css({149 'background': 'url(' + this.cbParallaxPublic.overlay_options.overlay_path + this.cbParallaxPublic.overlay_options.overlay_image + ')',291 $instance.overlayContainer = $('#cb_parallax_overlay'); 292 let overlayBackgroundColor = $instance.cbParallaxPublic.image_options.overlay_color; 293 let overlayOpacity = $instance.extractOpacity($instance.cbParallaxPublic.image_options.overlay_opacity); 294 295 $instance.overlayContainer.css({ 296 'background': 'url(' + $instance.cbParallaxPublic.overlay_options.overlay_path + $instance.cbParallaxPublic.overlay_options.overlay_image + ')', 150 297 'opacity': overlayOpacity, 151 298 'background-color': overlayBackgroundColor … … 154 301 }, 155 302 156 getBackgroundMode: function() {303 /*getBackgroundMode: function() { 157 304 let mode = 'static'; 158 305 159 if ('1' === this.parallaxEnabled && '1' === this.canParallax) {160 mode = ' parallax';306 if ('1' === $instance.parallaxEnabled && '1' === $instance.canParallax) { 307 mode = 'Parallax'; 161 308 } 162 309 163 310 return mode; 164 }, 311 },*/ 165 312 166 313 /// Image Scaling 167 scaleImageVertical: function(imgWidth, imgHeight, viewportWidth, viewportHeight) { 168 // Zielhöhe: 125% der Viewport-Höhe 169 const targetHeight = viewportHeight * 1.25; 170 171 // Berechne Skalierung, um Höhe zu erreichen 172 const scale = targetHeight / imgHeight; 173 174 // Skaliere Breite entsprechend 175 let newWidth = imgWidth * scale; 176 let newHeight = imgHeight * scale; 177 178 // Wenn neue Breite kleiner als Viewport-Breite → anpassen 179 if (newWidth < viewportWidth) { 180 const scaleW = viewportWidth / imgWidth; 181 newWidth = imgWidth * scaleW; 182 newHeight = imgHeight * scaleW; 314 scaleImageForVerticalScrolling: function(imgW, imgH, viewportW, viewportH, scaleFactor) { 315 const targetW = viewportW; 316 const targetH = viewportH * scaleFactor; 317 318 let newW = targetW; 319 let newH = imgH / imgW * targetW; 320 321 // Skalieren der Bildbreite und -höhe auf die Mindestmasse 322 if (newH < targetH || newW < viewportW) { 323 while (newW < viewportW || newH < targetH) { 324 newW += 1; 325 newH += 1; 326 } 327 } 328 329 return { 330 width: newW.toFixed(0), 331 height: newH.toFixed(0) 332 }; 333 }, 334 335 scaleImageForHorizontalScrolling: function(imgW, imgH, viewportW, viewportH, scaleFactor) { 336 // Zielbreite: 125% der Viewport-Breite 337 const targetWidth = viewportW * scaleFactor; 338 339 // Berechne Skalierung, um Breite zu erreichen 340 const scale = targetWidth / imgW; 341 342 // Skaliere Höhe entsprechend 343 let newWidth = imgW * scale; 344 let newHeight = imgH * scale; 345 346 // Wenn neue Höhe kleiner als Viewport-Höhe → anpassen 347 if (newHeight < viewportH) { 348 const scaleH = viewportH / imgH; 349 newWidth = imgW * scaleH; 350 newHeight = imgH * scaleH; 183 351 } 184 352 … … 189 357 }, 190 358 191 scaleImageHorizontal: function(imgWidth, imgHeight, viewportWidth, viewportHeight) {192 // Zielbreite: 125% der Viewport-Breite193 const targetWidth = viewportWidth * 1.25;194 195 // Berechne Skalierung, um Breite zu erreichen196 const scale = targetWidth / imgWidth;197 198 // Skaliere Höhe entsprechend199 let newWidth = imgWidth * scale;200 let newHeight = imgHeight * scale;201 202 // Wenn neue Höhe kleiner als Viewport-Höhe → anpassen203 if (newHeight < viewportHeight) {204 const scaleH = viewportHeight / imgHeight;205 newWidth = imgWidth * scaleH;206 newHeight = imgHeight * scaleH;207 }208 209 return {210 width: newWidth.toFixed(0),211 height: newHeight.toFixed(0)212 };213 },214 215 359 /// Moves 216 doParallaxBackgroundImage : function() {217 this.updateCanvasAlignment();218 this.updateParallaxAxis();360 doParallaxBackgroundImageMovement: function() { 361 $instance.updateCanvasAlignment(); 362 $instance.updateParallaxAxis(); 219 363 // We call this one once from here so everything is Radiohead, Everything in its right place :) 220 this.doParallaxTranslate3DTransform(this.getParallaxTransform());364 $instance.doParallaxTranslate3DTransform($instance.getParallaxTransform()); 221 365 }, 222 366 … … 224 368 let element = $('#cb_parallax_canvas'); 225 369 226 if ('vertical' === this.direction) {227 element.css({'left': this.getBackgroundImageHorizontalAlignment()});228 } else if ('horizontal' === this.direction) {229 element.css({'top': this.getBackgroundImageVerticalAlignment()});370 if ('vertical' === $instance.direction) { 371 element.css({'left': $instance.getBackgroundImageHorizontalAlignment()}); 372 } else if ('horizontal' === $instance.direction) { 373 element.css({'top': $instance.getBackgroundImageVerticalAlignment()}); 230 374 } 231 375 }, … … 234 378 let element = $("#cb_parallax_canvas"); 235 379 236 if ('vertical' === this.direction) {237 if ('to bottom' === this.verticalScrollDirection) {380 if ('vertical' === $instance.direction) { 381 if ('to bottom' === $instance.verticalScrollDirection) { 238 382 element.css({ 239 383 'position': 'fixed', 240 'top': this.getBackgroundImageVerticalPositionInPx()384 'top': $instance.getBackgroundImageVerticalPositionInPx() 241 385 }); 242 386 } 243 } else if ('horizontal' === this.direction) {387 } else if ('horizontal' === $instance.direction) { 244 388 element.css({ 245 389 'position': 'fixed', 246 'left': this.getBackgroundImageHorizontalPositionInPx()390 'left': $instance.getBackgroundImageHorizontalPositionInPx() 247 391 }); 248 392 } 249 393 }, 394 395 /*considerAdminBar: function() { 396 if(0 !== $('#wpadminbar').length) { 397 let posTop = $('#wpadminbar').height(); 398 } 399 400 },*/ 250 401 251 402 /// Image Movement … … 265 416 y: null 266 417 }; 267 let ratio = this.getParallaxScrollRatio();418 let ratio = $instance.getScrollRatio(); 268 419 let scrollingPosition = $(window).scrollTop(); 269 420 270 421 // Determines the values for the transformation. 271 if ('vertical' === this.direction) {272 if ('to top' === this.verticalScrollDirection) {422 if ('vertical' === $instance.direction) { 423 if ('to top' === $instance.verticalScrollDirection) { 273 424 transform.x = 0; 274 425 transform.y = -scrollingPosition * ratio; 275 } else if ('to bottom' === this.verticalScrollDirection) {426 } else if ('to bottom' === $instance.verticalScrollDirection) { 276 427 transform.x = 0; 277 428 transform.y = scrollingPosition * ratio; 278 429 } 279 } else if ('horizontal' === this.direction) {280 if ('to the left' === this.horizontalScrollDirection) {430 } else if ('horizontal' === $instance.direction) { 431 if ('to the left' === $instance.horizontalScrollDirection) { 281 432 transform.x = -scrollingPosition * ratio; 282 433 transform.y = 0; 283 } else if ('to the right' === this.horizontalScrollDirection) {434 } else if ('to the right' === $instance.horizontalScrollDirection) { 284 435 transform.x = scrollingPosition * ratio; 285 436 transform.y = 0; … … 290 441 291 442 parallaxOnScroll: function(event) { 292 let $this = this;443 let $this = $instance; 293 444 294 445 if (undefined !== event) { … … 296 447 } 297 448 $this.isScrolling = '1'; 298 $instance = $this;299 449 requestAnimationFrame($this.scrollParallaxBackgroundImage); 300 450 }, … … 309 459 310 460 parallaxOnResize: function(event) { 311 let $this = this;312 461 let $this = $instance; 462 $this.canvasDim = $this.getCanvasDimensions(); 313 463 if (undefined !== event) { 314 464 $this = event.data.context; 315 465 } 316 466 $this.isResizing = '1'; 317 $instance = $this;318 467 requestAnimationFrame($this.resizeParallaxBackgroundImage); 319 468 }, … … 333 482 getBackgroundImageHorizontalAlignment: function() { 334 483 let posX = null; 335 let canvasDim = this.getCanvasDimensions();336 let aspectRatio = this.getViewportAspectRatio();337 let landscape = aspectRatio >= this.imageAspectRatio ? '1' : '0';338 let portrait = aspectRatio < this.imageAspectRatio ? '1' : '0';339 let viewport = $(window);340 341 if ('vertical' === this.direction) {342 if ('to top' === this.verticalScrollDirection) {484 let canvasDim = $instance.getCanvasDimensions(); 485 let aspectRatio = $instance.getViewportAspectRatio(); 486 let landscape = aspectRatio >= $instance.imageAspectRatio ? '1' : '0'; 487 let portrait = aspectRatio < $instance.imageAspectRatio ? '1' : '0'; 488 //let viewport = $(window); 489 490 if ('vertical' === $instance.direction) { 491 if ('to top' === $instance.verticalScrollDirection) { 343 492 if ('1' === landscape) { 344 493 switch (this.horizontalAlignment) { … … 355 504 return parseInt(posX) + 'px'; 356 505 } else if ('1' === portrait) { 357 switch ( this.horizontalAlignment) {506 switch ($instance.horizontalAlignment) { 358 507 case 'left': 359 508 posX = '0'; … … 368 517 return parseInt(posX) + 'px'; 369 518 } 370 } else if ('to bottom' === this.verticalScrollDirection) {519 } else if ('to bottom' === $instance.verticalScrollDirection) { 371 520 if ('1' === landscape) { 372 switch ( this.horizontalAlignment) {521 switch ($instance.horizontalAlignment) { 373 522 case 'left': 374 523 posX = '0'; … … 383 532 return parseInt(posX) + 'px'; 384 533 } else if ('1' === portrait) { 385 switch ( this.horizontalAlignment) {534 switch ($instance.horizontalAlignment) { 386 535 case 'left': 387 536 posX = '0'; … … 402 551 getBackgroundImageVerticalAlignment: function() { 403 552 let posY = null; 404 let canvasDim = this.getCanvasDimensions();405 let aspectRatio = this.getViewportAspectRatio();406 let landscape = aspectRatio >= this.imageAspectRatio ? '1' : '0';407 let portrait = aspectRatio < this.imageAspectRatio ? '1' : '0';408 let viewport = $(window);409 410 if ('horizontal' === this.direction) {411 if ('to the left' === this.horizontalScrollDirection) {553 let canvasDim = $instance.getCanvasDimensions(); 554 let aspectRatio = $instance.getViewportAspectRatio(); 555 let landscape = aspectRatio >= $instance.imageAspectRatio ? '1' : '0'; 556 let portrait = aspectRatio < $instance.imageAspectRatio ? '1' : '0'; 557 //let viewport = $(window); 558 559 if ('horizontal' === $instance.direction) { 560 if ('to the left' === $instance.horizontalScrollDirection) { 412 561 if ('1' === landscape) { 413 switch ( this.verticalAlignment) {562 switch ($instance.verticalAlignment) { 414 563 case 'top': 415 564 posY = '0'; … … 425 574 return parseInt(posY) + 'px'; 426 575 } else if ('1' === portrait) { 427 switch ( this.verticalAlignment) {576 switch ($instance.verticalAlignment) { 428 577 case 'top': 429 578 posY = '0'; … … 439 588 return parseInt(posY) + 'px'; 440 589 } 441 } else if ('to the right' === this.horizontalScrollDirection) {590 } else if ('to the right' === $instance.horizontalScrollDirection) { 442 591 if ('1' === landscape) { 443 switch ( this.verticalAlignment) {592 switch ($instance.verticalAlignment) { 444 593 case 'top': 445 594 posY = '0'; … … 455 604 return parseInt(posY) + 'px'; 456 605 } else if ('1' === portrait) { 457 switch ( this.verticalAlignment) {606 switch ($instance.verticalAlignment) { 458 607 case 'top': 459 608 posY = '0'; … … 473 622 }, 474 623 475 get ParallaxScrollRatio: function() {476 let canvasDim = this.getCanvasDimensions();624 getScrollRatio: function() { 625 let canvasDim = $instance.getCanvasDimensions(); 477 626 let documentOffsetX = null; 478 627 let imageOffsetY = null; 479 628 let imageOffsetX = null; 480 629 let ratio = null; 481 let viewport = $(window);482 483 if ('vertical' === this.direction) {630 //let viewport = $(window); 631 632 if ('vertical' === $instance.direction) { 484 633 documentOffsetX = $(document).innerHeight() - viewport.innerHeight(); 485 634 imageOffsetY = canvasDim.y - viewport.height(); 486 635 ratio = (imageOffsetY / documentOffsetX); 487 } else if ('horizontal' === this.direction) {636 } else if ('horizontal' === $instance.direction) { 488 637 documentOffsetX = $(document).innerHeight() - viewport.innerHeight(); 489 638 imageOffsetX = canvasDim.x - viewport.innerWidth(); … … 493 642 }, 494 643 495 getViewportDimensions: function() {496 let viewport = $('window');497 return {height: viewport.innerHeight(), width: viewport.innerWidth()};498 },499 500 644 getCanvasDimensions: function() { 501 let viewport = $(window);502 645 let displayRatio = viewport.innerWidth() / viewport.innerHeight(); 503 let imageRatio = this.image.width / this.image.height;646 let imageRatio = $instance.image.width / $instance.image.height; 504 647 let imageHeight = 0; 505 648 let imageWidth = 0; 506 649 507 if ('vertical' === this.direction) {650 if ('vertical' === $instance.direction) { 508 651 509 652 if (imageRatio < displayRatio) { 510 653 imageWidth = viewport.innerWidth(); 511 imageHeight = imageWidth / this.image.width * this.image.height; 512 return {x: imageWidth.toFixed(0), y: imageHeight.toFixed(0)}; 654 imageHeight = imageWidth / $instance.image.width * $instance.image.height; 513 655 } else { 514 imageHeight = viewport.innerHeight() * this.parallaxfactor; 515 imageWidth = imageHeight / this.image.height * this.image.width; 516 return {x: imageWidth.toFixed(0), y: imageHeight.toFixed(0)}; 656 imageHeight = viewport.innerHeight() * $instance.scrollFactor; 657 imageWidth = imageHeight / $instance.image.height * $instance.image.width; 517 658 } 518 } 519 if ('horizontal' === this.direction) { 659 return {x: imageWidth.toFixed(0), y: imageHeight.toFixed(0)}; 660 } 661 if ('horizontal' === $instance.direction) { 520 662 521 663 if (imageRatio < displayRatio) { 522 imageWidth = viewport.innerWidth() * this.parallaxfactor; 523 imageHeight = imageWidth / this.image.width * this.image.height; 524 return {x: imageWidth.toFixed(0), y: imageHeight.toFixed(0)}; 664 imageWidth = viewport.innerWidth() * $instance.scrollFactor; 665 imageHeight = imageWidth / $instance.image.width * $instance.image.height; 525 666 } else { 526 667 imageHeight = viewport.innerHeight(); 527 imageWidth = imageHeight / this.image.height * this.image.width; 528 return {x: imageWidth.toFixed(0), y: imageHeight.toFixed(0)}; 668 imageWidth = imageHeight / $instance.image.height * $instance.image.width; 529 669 } 670 return {x: imageWidth.toFixed(0), y: imageHeight.toFixed(0)}; 530 671 } 531 672 }, … … 534 675 const viewportW = window.innerWidth; 535 676 const viewportH = window.innerHeight; 536 const imgW = this.image.width;537 const imgH = this.image.height;538 539 if ('vertical' === this.direction) {540 return this.scaleImageVertical(imgW, imgH, viewportW, viewportH);541 } 542 if ('horizontal' === this.direction) {543 return this.scaleImageHorizontal(imgW, imgH, viewportW, viewportH);677 const imgW = parseInt($instance.image.width); 678 const imgH = parseInt($instance.image.height); 679 let scaleFactor = {x: 1.25, y: 1.25}; 680 if ('vertical' === $instance.direction) { 681 return $instance.scaleImageForVerticalScrolling(imgW, imgH, viewportW, viewportH, scaleFactor.x); 682 } 683 if ('horizontal' === $instance.direction) { 684 return $instance.scaleImageForHorizontalScrolling(imgW, imgH, viewportW, viewportH, scaleFactor.y); 544 685 } 545 686 }, 546 687 547 688 updateCanvasDimensions: function() { 548 let canvasDim = this.getCanvasDimensions();689 let canvasDim = $instance.getCanvasDimensions(); 549 690 let canvas = $("#cb_parallax_canvas"); 550 691 let canvasWidth = parseInt(canvasDim.x); … … 552 693 canvas.width(canvasWidth); 553 694 canvas.height(canvasHeight); 554 },555 556 setupStaticBackgroundImageContainer: function() {557 let canvasDim = this.getStaticBackgroundImageDimensions();558 559 $('body').css({560 'background': 'url(' + this.image.src + ')',561 'background-size': canvasDim.width + 'px' + ' ' + canvasDim.height + 'px',562 'background-position': this.image.positionX + ' ' + this.image.positionY,563 'background-attachment': this.image.backgroundAttachment,564 'background-repeat': this.image.backgroundRepeat565 });566 },567 568 staticBackgroundImageOnResize: function(event) {569 let $this = this;570 571 if (undefined !== event) {572 $this = event.data.context;573 }574 $this.isResizing = '1';575 $instance = $this;576 requestAnimationFrame($this.updateStaticBackgroundImageAlignment);577 },578 579 updateStaticBackgroundImageAlignment: function() {580 if ('1' === $instance.isResizing) {581 $instance.updateStaticBackgroundImageDimensions();582 }583 $instance.isResizing = '0';584 requestAnimationFrame($instance.updateStaticBackgroundImageAlignment);585 },586 587 updateStaticBackgroundImageDimensions: function() {588 let canvasDim = $instance.getStaticBackgroundImageDimensions();589 $('body').css({'background-size': canvasDim.width + 'px' + ' ' + canvasDim.height + 'px'});590 },591 592 getStaticBackgroundImageDimensions: function() {593 let viewportSize = this.getViewportDimensions();594 let canvasDim = {};595 596 if (this.getViewportAspectRatio() >= this.imageAspectRatio) {597 // Landscape598 canvasDim.width = viewportSize.width;599 canvasDim.height = canvasDim.width / this.imageAspectRatio;600 return (canvasDim);601 } else {602 // Portrait603 canvasDim.height = viewportSize.height;604 canvasDim.width = canvasDim.height * this.imageAspectRatio;605 return canvasDim;606 }607 608 695 }, 609 696 … … 626 713 getBackgroundImageHorizontalPositionInPx: function() { 627 714 let posX = null; 628 let canvasDimensions = this.getCanvasDimensions();629 630 if ('to the left' === this.horizontalScrollDirection) {715 let canvasDimensions = $instance.getCanvasDimensions(); 716 717 if ('to the left' === $instance.horizontalScrollDirection) { 631 718 posX = 0; 632 719 return posX.toString() + 'px'; 633 } else if ('to the right' === this.horizontalScrollDirection) {720 } else if ('to the right' === $instance.horizontalScrollDirection) { 634 721 let number = $(window).innerWidth() - canvasDimensions.x; 635 722 posX = parseInt(number.toFixed()); … … 640 727 getBackgroundImageVerticalPositionInPx: function() { 641 728 let posY = null; 642 let canvasDimensions = this.getCanvasDimensions();643 644 if ('to top' === this.verticalScrollDirection) {729 let canvasDimensions = $instance.getCanvasDimensions(); 730 731 if ('to top' === $instance.verticalScrollDirection) { 645 732 posY = 0; 646 733 return posY.toString() + 'px'; 647 } else if ('to bottom' === this.verticalScrollDirection) {734 } else if ('to bottom' === $instance.verticalScrollDirection) { 648 735 let number = $(window).innerHeight() - canvasDimensions.y; 649 736 posY = parseInt(number.toFixed()); … … 653 740 654 741 getBackgroundImageAspectRatio: function() { 655 let image = this.image;656 return image.width / image.height;742 let image = $instance.image; 743 return (image.width / image.height).toFixed(2); 657 744 }, 658 745 659 746 getViewportAspectRatio: function() { 660 let viewport = $(window);661 return viewport.innerWidth() / viewport.innerHeight();747 //let viewport = $(window); 748 return (viewport.innerWidth() / viewport.innerHeight()).toFixed(2); 662 749 }, 663 750 … … 665 752 let result = string.match(/\d+/g); 666 753 return result[0] + "." + result[1]; 754 }, 755 756 ////////////////////////////////////////// 757 758 // Effects 759 clampMovement: function(x, y, element) { 760 const maxX = element.offsetWidth * 0.2; 761 const maxY = element.offsetHeight * 0.2; 762 return [ 763 Math.max(-maxX, Math.min(maxX, x)), 764 Math.max(-maxY, Math.min(maxY, y)) 765 ]; 766 }, 767 768 spiralScroll: function(e, s) { 769 let r = s * 0.1, a = s * 0.01, x = r * Math.cos(a), y = r * Math.sin(a); 770 [x, y] = $instance.clampMovement(x, y, e); 771 e.style.transform = `translate3d(${x}px,${y}px,0)`; 772 }, 773 774 sineWaveFloat: function(e, s) { 775 let a = e.offsetWidth * 0.2, x = a * Math.sin(s * 0.01), y = s * 0.5; 776 [x, y] = $instance.clampMovement(x, y, e); 777 e.style.transform = `translate3d(${x}px,${y}px,0)`; 778 }, 779 780 goldenRatioScale: function(e, s) { 781 let scale = Math.min(1.2, 1 + s * 0.0001 * 1.618); 782 e.style.transform = `scale(${scale})`; 783 }, 784 785 fibonacciPath: function(e, s) { 786 let f = s / 100, a = f * (Math.PI / 3), r = f * 5, x = r * Math.cos(a), y = r * Math.sin(a); 787 [x, y] = $instance.clampMovement(x, y, e); 788 e.style.transform = `translate3d(${x}px,${y}px,0)`; 789 }, 790 791 radialOutwardMovement: function(e, s) { 792 let a = Math.PI / 4, d = s * 0.3, x = d * Math.cos(a), y = d * Math.sin(a); 793 [x, y] = $instance.clampMovement(x, y, e); 794 e.style.transform = `translate3d(${x}px,${y}px,0)`; 795 }, 796 797 orbitalLayers: function(e, s) { 798 let r = e.offsetWidth * 0.2, a = s * 0.01, x = r * Math.cos(a), y = r * Math.sin(a); 799 [x, y] = $instance.clampMovement(x, y, e); 800 e.style.transform = `translate3d(${x}px,${y}px,0)`; 801 }, 802 803 tornadoTwirl: function(e, s) { 804 let y = s * 0.5, a = s * 0.1; 805 [, y] = $instance.clampMovement(0, y, e); 806 e.style.transform = `translate3d(0,${y}px,0) rotate(${a}deg)`; 807 }, 808 809 diagonalParallax: function(e, s) { 810 let x = s * 0.3, y = s * 0.7; 811 [x, y] = $instance.clampMovement(x, y, e); 812 e.style.transform = `translate3d(${x}px,${y}px,0)`; 813 }, 814 815 oceanWaveLayers: function(e, s) { 816 let a = e.offsetWidth * 0.2, x = a * Math.sin(s * 0.02), y = s * 0.4; 817 [x, y] = $instance.clampMovement(x, y, e); 818 e.style.transform = `translate3d(${x}px,${y}px,0)`; 819 }, 820 821 vortexInOut: function(e, s) { 822 let sc = Math.min(1.2, 1 + s * 0.0002), a = s * 0.2; 823 e.style.transform = `rotate(${a}deg) scale(${sc})`; 824 }, 825 826 perspectiveFlip: function(e, s) { 827 let a = s * 0.1; 828 e.style.transform = `rotateX(${a}deg) scale(1.2)`; 829 e.style.transformStyle = 'preserve-3d'; 830 }, 831 832 randomDrift: function(e, s) { 833 let x = Math.sin(s * 0.01) * e.offsetWidth * 0.2, y = Math.cos(s * 0.01) * e.offsetHeight * 0.2; 834 [x, y] = $instance.clampMovement(x, y, e); 835 e.style.transform = `translate3d(${x}px,${y}px,0)`; 836 }, 837 838 depthFog: function(e, s) { 839 let y = s * 0.5, b = Math.min(s * 0.01, 5); 840 [, y] = $instance.clampMovement(0, y, e); 841 e.style.transform = `translateY(${y}px)`; 842 e.style.filter = `blur(${b}px)`; 843 }, 844 845 parallaxStars: function(e, s) { 846 let y = s * 0.2; 847 [, y] = $instance.clampMovement(0, y, e); 848 e.style.transform = `translateY(${y}px)`; 849 }, 850 851 logarithmicSpiral: function(e, s) { 852 let b = 0.1, t = s * 0.01, r = Math.exp(b * t) * 5, x = r * Math.cos(t), y = r * Math.sin(t); 853 [x, y] = $instance.clampMovement(x, y, e); 854 e.style.transform = `translate3d(${x}px,${y}px,0)`; 855 }, 856 857 gridMorph: function(e, s) { 858 let sk = s * 0.05; 859 e.style.transform = `skew(${sk}deg,${sk}deg)`; 860 }, 861 862 pathFollowing: function(e, s) { 863 let t = (s % 1000) / 1000, x = 500 * Math.cos(2 * Math.PI * t), y = 500 * Math.sin(2 * Math.PI * t); 864 [x, y] = $instance.clampMovement(x, y, e); 865 e.style.transform = `translate3d(${x}px,${y}px,0)`; 866 }, 867 868 magneticEasing: function(e, s) { 869 let x = Math.sin(s * 0.01) * e.offsetWidth * 0.2; 870 [x] = $instance.clampMovement(x, 0, e); 871 e.style.transform = `translateX(${x}px)`; 872 }, 873 874 infiniteLoop: function(e, s) { 875 let y = s % e.offsetHeight; 876 [, y] = $instance.clampMovement(0, y, e); 877 e.style.transform = `translateY(${y}px)`; 667 878 } 668 879 -
cb-parallax/tags/0.9.9/vendor/smoothscroll/smoothscroll.js
r3330924 r3334980 147 147 * @method isScrollable 148 148 * @param {Node} el 149 * @param {String} axis150 149 * @returns {Boolean} 151 150 */
Note: See TracChangeset
for help on using the changeset viewer.