p5.Element

एक HTMLElement का वर्णन करने के लिए एक क्लास|

स्केच कई तत्वों का उपयोग कर सकते हैं। सामान्य तत्वों में ड्राइंग कैनवास, बटन, स्लाइडर, वेबकैम फ़ीड इत्यादि शामिल हैं।

सभी तत्व p5.Element वर्ग के तरीकों को साझा करते हैं। वे createCanvas() और createButton() जैसे फ़ंक्शंस के साथ बनाए गए हैं।

उदाहरण

सिंटैक्स

p5.Element(elt, [pInst])

पैरामीटर्स

elt

तत्व जो DOM तत्व को घेरता है।

pInst

p5 उदाहरण के लिए पॉइंटर।

मेथड्स

parent

तत्व को मूल तत्व से जोड़ता है।

उदाहरण के लिए, एक

तत्व का उपयोग टेक्स्ट के दो टुकड़े, एक हेडर और एक पैराग्राफ रखने के लिए एक बॉक्स के रूप में किया जा सकता है।
हेडर और पैराग्राफ दोनों का मूल तत्व है।

पैरामीटर parent के तीन प्रकारों में से एक हो सकता है। parent मूल तत्व की आईडी के साथ एक स्ट्रिंग हो सकता है, जैसा कि myElement.parent('container') में है। यह एक अन्य p5.Element ऑब्जेक्ट भी हो सकता है, जैसा कि myElement.parent(myDiv) में है। अंततः, parent हो सकता है एक HTMLElement ऑब्जेक्ट, जैसे myElement.parent(anotherElement)|

बिना किसी तर्क के myElement.parent() को कॉल करने से तत्व का पैरेंट वापस आ जाता है।

id

किसी दिए गए स्ट्रिंग का उपयोग करके तत्व की आईडी सेट करता है।

बिना किसी तर्क के myElement.id() पर कॉल करने पर उसकी आईडी स्ट्रिंग के रूप में वापस आ जाती है।

class

किसी दिए गए स्ट्रिंग का उपयोग करके तत्व के लिए वर्ग विशेषता जोड़ता है।

बिना किसी तर्क के myElement.class() कॉल करने पर अपनी वर्तमान वर्ग विशेषताओं की एक स्ट्रिंग वापस करता है।

mousePressed

जब माउस को तत्व पर दबाया जाता है तो ये फ़ंक्शन कॉल होता है।

myElement.mousePressed(false) कॉल करने से तत्व डिसेबल्ड हो जाता है |

ध्यान दें: कुछ मोबाइल ब्राउज़र भी इस घटना को ट्रिगर कर सकते हैं जब तत्व एक त्वरित टैप प्राप्त करता है।

doubleClicked

जब माउस को तत्व पर दो बार दबाया जाता है तो एक फ़ंक्शन कॉल होता है।

myElement.doubleClicked(false) कॉल करने से वो डिसेबल्ड हो जाता है |

mouseWheel

जब माउस व्हील तत्व पर स्क्रॉल करता है तो ये फ़ंक्शन कॉल होता है।

कॉलबैक फ़ंक्शन, fxn, को एक event ऑब्जेक्ट दिया जाता है | event ऑब्जेक्ट में दो संख्यात्मक गुण होते हैं: deltaX और deltaY। यदि माउस व्हील उपयोगकर्ता से दूर घूमता है तो event.deltaY संख्यात्मक रूप से नकारात्मक है, और यदि माउस व्हील उपयोगकर्ता की ओर घूमता है तो यह संख्यात्मक रूप से सकारात्मक है। यदि माउस व्हील दाईं ओर चलता है तो event.deltaX संख्यात्मक रूप से सकारात्मक है, और यदि माउस व्हील बाईं ओर चलता है तो यह नकारात्मक है |

myElement.mouseWheel(false) कॉल करने से वो डिसेबल्ड हो जाता है |

mouseReleased

जब माउस को तत्व पर छोड़ा जाता है तो ये फ़ंक्शन कॉल होता है।

myElement.mouseReleased(false) कॉल करने से वो डिसेबल्ड हो जाता है |

ध्यान दें: कुछ मोबाइल ब्राउज़र भी इस घटना को ट्रिगर कर सकते हैं जब तत्व एक त्वरित टैप प्राप्त करटा है।

mouseClicked

जब माउस तत्व पर दबाया और उसके ऊपर छोड़ा जाता है तो ये फ़ंक्शन कॉल होता है |

myElement.mouseReleased(false) कॉल करने से ये फंक्शन डिसेबल्ड हो जाता है |

ध्यान दें: कुछ मोबाइल ब्राउज़र भी इस घटना को ट्रिगर कर सकते हैं जब तत्व एक त्वरित टैप प्राप्त करटा है।

mouseMoved

जब माउस तत्व पर चलता है तो तो ये फ़ंक्शन कॉल होता है।

myElement.mouseMoved(false) कॉल करने से ये फंक्शन डिसेबल्ड हो जाता है |

mouseOver

जब माउस तत्व पर जाता है तो ये फ़ंक्शन कॉल होता है।

myElement.mouseOver(false) कॉल करने से ये फंक्शन डिसेबल्ड हो जाता है|

mouseOut

जब माउस तत्व से हट जाता है तो ये फ़ंक्शन कॉल होता है।

myElement.mouseOut(false) कॉल करने से ये फंक्शन डिसेबल्ड हो जाता है |

touchStarted

तत्व को छूने पर ये फ़ंक्शन कॉल होता है।

myElement.touchStarted(false) कॉल करने से ये फंक्शन डिसेबल्ड हो जाता है |

ध्यान दें: स्पर्श फ़ंक्शन केवल मोबाइल उपकरणों पर काम करते हैं।

touchMoved

जब उपयोगकर्ता तत्व को छूता है और चलता है तो ये फ़ंक्शन कॉल होता है।

myElement.touchMoved(false) कॉल करने से ये फंक्शन डिसेबल्ड हो जाता है |

ध्यान दें: स्पर्श फ़ंक्शन केवल मोबाइल उपकरणों पर काम करते हैं।

touchEnded

जब उपयोगकर्ता तत्व को छूना बंद कर देता है तो ये फ़ंक्शन कॉल होता है।

myElement.touchMoved(false) कॉल करने से ये फंक्शन डिसेबल्ड हो जाता है |

ध्यान दें: स्पर्श फ़ंक्शन केवल मोबाइल उपकरणों पर काम करते हैं।

dragOver

जब किसी फ़ाइल को तत्व पर खींचा जाता है तो फ़ंक्शन को कॉल करता है।

myElement.dragOver(false) कॉल करने से ये फंक्शन डिसेबल्ड हो जाता है |

dragLeave

जब किसी फ़ाइल को तत्व से खींचा जाता है तो एक फ़ंक्शन को कॉल करता है।

myElement.dragLeave(false) कॉल करने से ये फंक्शन डिसेबल्ड हो जाता है |

addClass

तत्व में एक वर्ग जोड़ता है।

removeClass

तत्व से एक वर्ग हटाता है।

hasClass

जांचता है कि क्या कोई वर्ग पहले से ही तत्व पर लागू है।

toggleClass

टॉगल करता है कि तत्व पर कोई वर्ग लागू है या नहीं।

child

Attaches the element as a child of another element.

myElement.child() accepts either a string ID, डोम node, or p5.Element. For example, myElement.child(otherElement). If no argument is provided, an array of children डोम nodes is returned.

center

Centers the element either vertically, horizontally, or both.

center() will center the element relative to its parent or according to the page's body if the element has no parent.

If no argument is passed, as in myElement.center() the element is aligned both vertically and horizontally.

html

Sets the inner HTML of the element, replacing any existing HTML.

The second parameter, append, is optional. If true is passed, as in myElement.html('hi', true), the HTML is appended instead of replacing existing HTML.

If no arguments are passed, as in myElement.html(), the element's inner HTML is returned.

position

Sets the element's position.

The first two parameters, x and y, set the element's position relative to the top-left corner of the web page.

The third parameter, positionType, is optional. It sets the element's positioning scheme. positionType is a string that can be either 'static', 'fixed', 'relative', 'sticky', 'initial', or 'inherit'.

If no arguments passed, as in myElement.position(), the तरीका returns the element's position in an object, as in { x: 0, y: 0 }.

style

Applies a style to the element by adding a CSS declaration.

The first parameter, property, is a string. If the name of a style property is passed, as in myElement.style('color'), the तरीका returns the current value as a string or null if it hasn't been set. If a property:style string is passed, as in myElement.style('color:deeppink'), the तरीका sets the style property to value.

The second parameter, value, is optional. It sets the property's value. value can be a string, as in myElement.style('color', 'deeppink'), or a p5.Color object, as in myElement.style('color', myColor).

attribute

Adds an attribute to the element.

This तरीका is useful for advanced tasks. Most commonly-used attributes, such as id, can be set with their dedicated methods. For example, nextButton.id('next') sets an element's id attribute. Calling nextButton.attribute('id', 'next') has the same effect.

The first parameter, attr, is the attribute's name as a string. Calling myElement.attribute('align') returns the attribute's current value as a string or null if it hasn't been set.

The second parameter, value, is optional. It's a string used to set the attribute's value. For example, calling myElement.attribute('align', 'center') sets the element's horizontal alignment to center.

removeAttribute

Removes an attribute from the element.

The parameter attr is the attribute's name as a string. For example, calling myElement.removeAttribute('align') removes its align attribute if it's been set.

value

Returns or sets the element's value.

Calling myElement.value() returns the element's current value.

The parameter, value, is an optional number or string. If provided, as in myElement.value(123), it's used to set the element's value.

show

Shows the current element.

hide

Hides the current element.

size

तत्व की चौड़ाई और ऊंचाई सेट करता है।

बिना किसी तर्क के myElement.size() को कॉल करने से तत्व का आकार width और height गुणों के साथ एक ऑब्जेक्ट के रूप में वापस आ जाता है। उदाहरण के लिए, {width: 20, height: 10 }|

पहला पैरामीटर, width, वैकल्पिक है। यह तत्व की चौड़ाई निर्धारित करने के लिए उपयोग की जाने वाली संख्या है। myElement.size(10)

पर कॉल किया जा रहा है |

दूसरा पैरामीटर, height, भी वैकल्पिक है। यह एक संख्या है जिसका उपयोग तत्व की ऊंचाई निर्धारित करने के लिए किया जाता है। उदाहरण के लिए, myElement.size(20, 10) को कॉल करने से तत्व की चौड़ाई 20 पिक्सेल और ऊंचाई 10 पिक्सेल पर सेट हो जाती है।

निरंतर AUTO का उपयोग पहलू अनुपात को बनाए रखते हुए एक समय में एक आयाम को समायोजित करने के लिए किया जा सकता है, जो कि width / height है। उदाहरण के लिए, एक ऐसे तत्व पर विचार करें जो 200 पिक्सेल चौड़ा और 100 पिक्सेल लंबा है। myElement.size(20, AUTO) को कॉल करने से चौड़ाई 20 पिक्सल और ऊंचाई 10 पिक्सल पर सेट हो जाती है।

ध्यान दें: उन तत्वों के मामले में जिन्हें डेटा लोड करने की आवश्यकता है, जैसे कि छवियां, डेटा लोड होने तक myElement.size() पर कॉल करने की प्रतीक्षा करें।

remove

Removes the element, stops all audio/video streams, and removes all callback functions.

drop

Calls a function when the user drops a file on the element.

The first parameter, callback, is a function to call once the file loads. The callback function should have one parameter, file, that's a p5.File object. If the user drops multiple files on the element, callback, is called once for each file.

The second parameter, fxn, is a function to call when the browser detects one or more dropped files. The callback function should have one parameter, event, that's a DragEvent.

draggable

Makes the element draggable.

The parameter, elmnt, is optional. If another p5.Element object is passed, as in myElement.draggable(otherElement), the other element will become draggable.

Notice any errors or typos? Please let us know. Please feel free to edit src/core/p5.Element.js and open a pull request!

संबंधित संदर्भ