Posts

Showing posts from June, 2020
Share:

How to 'href' to the element even to the top margin of each div?

The following is html code I have written to store some of my favorite gradients and I wanted to link anchor to 'id="grad1"' and 'id="grad2"' even including the margin at the top. I thought the ':target:before' would work to provide the margin when those 'id's were targeted but that does not work for me somehow. When I link to the below html, it only links to the top of the content, not to the top of the margin of each div. we should add scroll-margin-top to each of your grads that is equal to the margin you apply. Example: #grad1 { margin-top: 200px; scroll-margin-top: 200px; } This way, anchors will scroll to the offset specified by the scroll-margin-top instead of the element border.

How do I check if an array includes a value in JavaScript?

What is the most concise and efficient way to find out if a JavaScript array contains a value? Modern browsers have Array#includes, which does exactly that and is widely supported by everyone except IE: console.log(['joe', 'jane', 'mary'].includes('jane')); //true You can also use Array#indexOf, which is less direct, but doesn't require polyfills for outdated browsers. Many frameworks also offer similar methods: jQuery: $.inArray(value, array, [fromIndex]) Underscore.js: _.contains(array, value) (also aliased as _.include and _.includes) Dojo Toolkit: dojo.indexOf(array, value, [fromIndex, findLast]) Prototype: array.indexOf(value) MooTools: array.indexOf(value) MochiKit: findValue(array, value) MS Ajax: array.indexOf(value) Ext: Ext.Array.contains(array, value) Lodash: _.includes(array, value, [from]) (is _.contains prior 4.0.0) Ramda: R.includes(value, array) Notice that some frameworks implement this as a function, while others add the function to

How to highlight a word in an HTML list form a string with JavaScript?

for(let i = 0; i < mostrarString.length; i++) { //break each sentence down to its own array of words let splitString = mostrarString[i].split(" "); let rebuiltString = ''; for(let j = 0; j < splitString.length; j++) { //if the word matches palabra variable and is the first occurrence in the sentence if(splitString[j] === palabra && splitString.indexOf(splitString[j]) === j){ //wrap it in a span tag rebuiltString += `<span style="color:red">${splitString[j]}</span>` } else { //otherwise add to new string as is rebuiltString += splitString[j] } //add a space except after last word if(i !== splitString.length - 1) { rebuiltString += " " } } const newItem = document.createElement('li'); //set the string as the innerhtml so the span tag renders newItem.innerHTML = rebuiltS

Find Rectangle Path WPF | Saatody | Amit Padhiyar

using Core.Converter; using Core.UI; using System.Collections.Generic; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; namespace Shape { public class PRectangle { public void CreateNewOne(Grid Parent) { Rectangle Rectangle = new Rectangle(); Rectangle.HorizontalAlignment = HorizontalAlignment.Stretch; Rectangle.VerticalAlignment = VerticalAlignment.Stretch; Rectangle.Margin = new Thickness(10, 10, 10, 10); Rectangle.Stroke = Brushes.Orange; Rectangle.StrokeThickness = 1; Parent.Children.Add(Rectangle); MyRectangle = Rectangle; Rectangle.Loaded += (sender, e) => { UpdatePoints(); }; CompositionTarget.Rendering += (sender, e) => { UpdatePoints(); //if (UIEvent.IsBusy == true) //{