Friday, March 24, 2023
Learning Code
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#
No Result
View All Result
Learning Code
No Result
View All Result
Home JavaScript

Resizing an image-map on resizing a container div – JavaScript – SitePoint Forums

learningcode_x1mckf by learningcode_x1mckf
December 13, 2022
in JavaScript
0
Time limit for notify – JavaScript – SitePoint Forums
74
SHARES
1.2k
VIEWS
Share on FacebookShare on Twitter


You might also like

Toolkit Allows JavaScript Devs to Program Embedded Devices – The New Stack

Select data value from grandparent div? – JavaScript – SitePoint

How to Handle Errors in JavaScript – Programming – MUO – MakeUseOf


web148



December 12, 2022, 5:03pm
#1

I do know that this jquery from David J. Bradshaw works as anticipated to resize an image-map on resizing the complete browser window.
I ponder if it may very well be doable to change the code to resize the image-map on resizing not of the entire window, however of a given component (a div, i.g.) containing the picture.
It might be doable?

/*! Picture Map Resizer
 *  Desc: Resize HTML imageMap to scaled picture.
 *  Copyright: (c) 2014-15 David J. Bradshaw - [email protected]
 *  License: MIT
 */

;(operate() {
  'use strict'

  operate scaleImageMap() 
    operate resizeMap() 
      operate resizeAreaTag(cachedAreaCoords, idx) 
        operate scale(coord) 
          var dimension = 1 === (isWidth = 1 - isWidth) ? 'width' : 'peak'
          return (
            padding[dimension] +
            Math.flooring(Quantity(coord) * scalingFactor[dimension])
          )
        

        var isWidth = 0
        areas[idx].coords = cachedAreaCoords
          .break up(',')
          .map(scale)
          .be a part of(',')
      

      var scalingFactor = 
        width: picture.width / picture.naturalWidth,
        peak: picture.peak / picture.naturalHeight,
      

      var padding = 
        width: parseInt(
          window.getComputedStyle(picture, null).getPropertyValue('padding-left'),
          10
        ),
        peak: parseInt(
          window.getComputedStyle(picture, null).getPropertyValue('padding-top'),
          10
        ),
      

      cachedAreaCoordsArray.forEach(resizeAreaTag)
    

    operate getCoords(e) 
      //Normalize coord-string to csv format with none area chars
      return e.coords.change(/ *, */g, ',').change(/ +/g, ',')
    

    operate debounce() 
      clearTimeout(timer)
      timer = setTimeout(resizeMap, 250)
    

    operate begin() 
      if (
        picture.width !== picture.naturalWidth 

    operate addEventListeners() 
      picture.addEventListener('load', resizeMap, false) //Detect late picture masses in IE11
      window.addEventListener('focus', resizeMap, false) //Address window being resized while on one other tab
      window.addEventListener('resize', debounce, false)
      window.addEventListener('readystatechange', resizeMap, false)
      doc.addEventListener('fullscreenchange', resizeMap, false)
    

    operate beenHere() 
      return 'operate' === typeof map._resize
    

    operate getImg(identify) 
      return doc.querySelector('img[usemap="' + name + '"]')
    

    operate setup() 
      areas = map.getElementsByTagName('space')
      cachedAreaCoordsArray = Array.prototype.map.name(areas, getCoords)
      picture = getImg('#' + map.identify) 

    var /*jshint validthis:true */
      map = this,
      areas = null,
      cachedAreaCoordsArray = null,
      picture = null,
      timer = null

    if (!beenHere()) 
      setup()
      addEventListeners()
      begin()
     else 
      map._resize() //Already setup, so simply resize map
    
  

  operate manufacturing unit() 
    operate chkMap(component) 
      if (!component.tagName) 
        throw new TypeError('Object will not be a sound DOM component')
       else if ('MAP' !== component.tagName.toUpperCase()) 
        throw new TypeError(
          'Anticipated <MAP> tag, discovered <' + component.tagName + '>.'
        )
      
    

    operate init(component) 
      if (component) 
        chkMap(component)
        scaleImageMap.name(component)
        maps.push(component)
      
    

    var maps

    return operate imageMapResizeF(goal) 
      maps = [] // Solely return maps from this name

      change (typeof goal)  'map'),
            init
          )
          break
        case 'object':
          init(goal)
          break
        default:
          throw new TypeError('Surprising knowledge sort (' + typeof goal + ').')
      

      return maps
    
  

  if (typeof outline === 'operate' && outline.amd) 
    outline([], manufacturing unit)
   else if (typeof module === 'object' && typeof module.exports === 'object') 
    module.exports = manufacturing unit() //Node for browserfy
   else 
    window.imageMapResize = manufacturing unit()
  

  if ('jQuery' in window) 
    window.jQuery.fn.imageMapResize = operate $imageMapResizeF() 
      return this.filter('map')
        .every(scaleImageMap)
        .finish()
    
  
})()


PaulOB



December 13, 2022, 3:04pm
#2

web148:

I ponder if it may very well be doable to change the code to resize the image-map on resizing not of the entire window, however of a given component (a div, i.g.) containing the picture.

It appears to do this already until I’m mistaken.



Source link

Share30Tweet19
learningcode_x1mckf

learningcode_x1mckf

Recommended For You

Toolkit Allows JavaScript Devs to Program Embedded Devices – The New Stack

by learningcode_x1mckf
March 23, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

Toolkit Allows JavaScript Devs to Program Embedded Devices  The New Stack Source link

Read more

Select data value from grandparent div? – JavaScript – SitePoint

by learningcode_x1mckf
March 23, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

Select data value from grandparent div? - JavaScript  SitePoint Source link

Read more

How to Handle Errors in JavaScript – Programming – MUO – MakeUseOf

by learningcode_x1mckf
March 23, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

How to Handle Errors in JavaScript - Programming  MUO - MakeUseOf Source link

Read more

How to Use the Javascript Slice Method – hackernoon.com

by learningcode_x1mckf
March 23, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

How to Use the Javascript Slice Method  hackernoon.com Source link

Read more

Clean Code in JavaScript – SitePoint

by learningcode_x1mckf
March 23, 2023
0
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

Clean Code in JavaScript  SitePoint Source link

Read more
Next Post
Context Managers and Python’s with Statement – Real Python

Context Managers and Python's with Statement – Real Python

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related News

Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

What Is C++? – Built In

March 18, 2023
Google expands open source bounties, will soon support Javascript fuzzing too – ZDNet

The top universities for C++ engineers – eFinancialCareers (US)

February 5, 2023
Coffee Beauty Products Market Is Projected To Rise At A Cagr Of 3.1% During 2026 – L’ORÉAL PARIS, Unilever, JAVA , Avon

Coffee Beauty Products Market Is Projected To Rise At A Cagr Of 3.1% During 2026 – L’ORÉAL PARIS, Unilever, JAVA , Avon

September 4, 2022

Browse by Category

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

RECENT POSTS

  • Java Developer Survey Reveals Increased Need for Java … – PR Newswire
  • What You Should Definitely Pay Attention to When Hiring Java Developers – Modern Diplomacy
  • Java Web Frameworks Software Market Research Report 2023 … – Los Alamos Monitor

CATEGORIES

  • C#
  • C++
  • Java
  • JavaScript
  • Python
  • Swift

© 2022 Copyright Learning Code

No Result
View All Result
  • Home
  • JavaScript
  • Java
  • Python
  • Swift
  • C++
  • C#

© 2022 Copyright Learning Code

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?